{"id":345,"date":"2015-08-04T19:32:54","date_gmt":"2015-08-04T23:32:54","guid":{"rendered":"http:\/\/csclub.uwaterloo.ca\/~k55chen\/?p=345"},"modified":"2017-04-23T01:10:18","modified_gmt":"2017-04-23T05:10:18","slug":"regression-with-a-large-dummy-variable-set-e-g-firm-and-year-fixed-effects","status":"publish","type":"post","link":"https:\/\/www.kaichen.work\/?p=345","title":{"rendered":"Regression with a large dummy-variable set (e.g., firm and year fixed effects) in Stata"},"content":{"rendered":"<p>I run a regression in Stata with a Compustat dataset that contains `fyear` and `gvkey`. I want to add firm and year fixed effects, so I type the following command:<\/p>\n<p>`regress DV IV i.fyear i.gvkey`<\/p>\n<p>But Stata returns the error r(103), which suggests &#8220;too many variables specified&#8221;. It turns out that the culprit is `i.gvkey`.<\/p>\n<p>I find two work-arounds:<\/p>\n<p>(1) Use both `xtset` and `xtreg`:<br \/>\n`xtset gvkey`<br \/>\n`xtreg DV IV i.fyear, fe`<\/p>\n<p>(2) Use `areg`:<br \/>\n`areg DV IV i.fyear, absorb(gvkey)`<\/p>\n<p>`xtreg` is the Stata command for fixed-, between-, and random-effects linear models, and `areg` is the Stata command for linear regression with a large dummy-variable set.<\/p>\n<p>In my example, I find that both commands returns exactly same results.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I run a regression in Stata with a Compustat dataset that contains `fyear` and `gvkey`. I want to add firm and year fixed effects, so I type the following command: `regress DV IV i.fyear i.gvkey` But Stata returns the error &hellip; <a href=\"https:\/\/www.kaichen.work\/?p=345\">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":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/345"}],"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=345"}],"version-history":[{"count":8,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions"}],"predecessor-version":[{"id":830,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions\/830"}],"wp:attachment":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}