{"id":429,"date":"2015-09-17T22:08:41","date_gmt":"2015-09-18T02:08:41","guid":{"rendered":"http:\/\/csclub.uwaterloo.ca\/~k55chen\/?p=429"},"modified":"2017-04-23T13:30:41","modified_gmt":"2017-04-23T17:30:41","slug":"proc-expand-in-sas-and-rolling-in-stata","status":"publish","type":"post","link":"https:\/\/www.kaichen.work\/?p=429","title":{"rendered":"Rolling-window computation in SAS and Stata"},"content":{"rendered":"<p>SASers often find `proc expand` plus\u00a0`transformout` very useful for rolling-window (or moving-window) computation. Stataers may wonder if there is a counter party in Stata. The answer is &#8220;yes&#8221;. The command in Stata is `rolling`. See the manual below:<\/p>\n<p><a href=\"http:\/\/www.stata.com\/manuals13\/tsrolling.pdf\">http:\/\/www.stata.com\/manuals13\/tsrolling.pdf<\/a><\/p>\n<p>The benefits of using \u00a0`rolling` in Stata comes from two facts:<\/p>\n<ul>\n<li>Stata is superior to SAS in dealing with time-series or panel data. After a single-line command to define time-series or panel data (`tsset`), Stata can handle gaps in time series intelligently and automatically. In contrast, SAS\u00a0users have to manually check gaps in time series. 90% of SAS codes using rolling-window transformation in accounting research do not have such gap check. This may generate incorrect inferences.<\/li>\n<li>In Stata, `rolling` can be combined with any other command such as `regress`. Therefore rolling-window computation in Stata is more flexible.<\/li>\n<\/ul>\n<p>However, `proc expand` plus `transformout` in SAS is insanely faster than `rolling` in Stata (by &#8220;insanely faster&#8221;, I mean maybe millions times faster). This is truly a deal breaker for Stata.<\/p>\n<p>Therefore, the best solution to rolling-window computation is to use Stata to do the gap check and filling (`tsfill`) first, and then use SAS to do lightening rolling-window computation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SASers often find `proc expand` plus\u00a0`transformout` very useful for rolling-window (or moving-window) computation. Stataers may wonder if there is a counter party in Stata. The answer is &#8220;yes&#8221;. The command in Stata is `rolling`. See the manual below: http:\/\/www.stata.com\/manuals13\/tsrolling.pdf The &hellip; <a href=\"https:\/\/www.kaichen.work\/?p=429\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,8,9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/429"}],"collection":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=429"}],"version-history":[{"count":12,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/429\/revisions"}],"predecessor-version":[{"id":481,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/429\/revisions\/481"}],"wp:attachment":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}