'Creating Dummy Variable for Two Events in Dataset and Restricting Regression by Time Period in Stata
I am testing effect to two events in a dataset with a time dummy variable (post). For instance, my first event is in 1999 so I want to post-period after 1999 to 2003. Similarly, my second event is in 2010 so I want to set post period after 2010 to 2014. Accordingly, I want to set dummy variable (post) equals 1 for observations after post period and 0 for the pre periods.
One way I understand is to make a separate dataset for both the events and run. However, is there is anyway I could accomplish the same on this dataset ?
Additionally, if I want to run a liner regression is there is any command I could look into to restrict the regression for each event period ? So for first event run the regression until 2003 and for the second event until 2014
Any suggestions would be great. Thank you in advance
* Example generated by -dataex-. For more info, type help dataex
clear
input str9 Ticker int Year str23 Industry double INBD float(ROA Size MTB LEV LOSS)
"TH:2S" 1995 "Industrials" .36363636363636365 . . . . 0
"TH:2S" 1996 "Industrials" .2857142857142857 . . . . 0
"TH:2S" 1997 "Industrials" .3333333333333333 . . . . 0
"TH:2S" 1998 "Industrials" .375 . . . . 0
"TH:2S" 1999 "Industrials" .625 . . . . 0
"TH:2S" 2000 "Industrials" .26666666666666666 . . . . 0
"TH:2S" 2001 "Industrials" .375 . . . . 0
"TH:2S" 2002 "Industrials" .21428571428571427 . . . . 0
"TH:2S" 2003 "Industrials" .25 . . . . 0
"TH:2S" 2004 "Industrials" .3333333333333333 . . . . 0
"TH:2S" 2005 "Industrials" .3333333333333333 . . . . 0
"TH:2S" 2006 "Industrials" 0 .05430601 13.347824 . .4487669 0
"TH:2S" 2007 "Industrials" .23076923076923078 .0748898 13.513892 . .405519 0
"TH:2S" 2008 "Industrials" .42857142857142855 .20173776 13.234512 . .3000143 0
"TH:2S" 2009 "Industrials" 0 .1005717 13.72495 1.1260449 .3933205 0
"TH:2S" 2010 "Industrials" .2727272727272727 .06970939 13.839908 1.0841182 .43828955 0
"TH:2S" 2011 "Industrials" .4 .06131507 13.873565 .9524283 .4303303 0
"TH:2S" 2012 "Industrials" 0 .04201316 14.04106 .9658951 .5001149 0
"TH:2S" 2013 "Industrials" 0 .05576677 14.014296 1.0163808 .4338268 0
"TH:2S" 2014 "Industrials" 0 .034753945 14.002456 1.6368295 .4192463 0
"TH:A" 1995 "Property & Construction" .45454545454545453 . . . . 0
"TH:A" 1996 "Property & Construction" .5 . . . . 0
"TH:A" 1997 "Property & Construction" 0 . . . . 0
"TH:A" 1998 "Property & Construction" .25 . . . . 0
"TH:A" 1999 "Property & Construction" .13333333333333333 . . . . 0
"TH:A" 2000 "Property & Construction" .4 . . . . 0
"TH:A" 2001 "Property & Construction" .5 . . . . 0
"TH:A" 2002 "Property & Construction" .6 . . . . 0
"TH:A" 2003 "Property & Construction" .3333333333333333 .025012556 14.53853 . .6812668 0
"TH:A" 2004 "Property & Construction" 0 .04457069 15.205904 1.6980723 .6221218 0
"TH:A" 2005 "Property & Construction" 0 .0020386886 15.268938 2.07966 .6608869 0
"TH:A" 2006 "Property & Construction" .3333333333333333 .001907199 15.27291 1.964063 .6603242 0
"TH:A" 2007 "Property & Construction" 0 -.015466996 15.44163 1.918302 .7279775 1
"TH:A" 2008 "Property & Construction" .5 .005696189 15.559473 1.776193 .7537934 0
"TH:A" 2009 "Property & Construction" .46153846153846156 .09692752 15.491538 1.440211 .6395585 0
"TH:A" 2010 "Property & Construction" .42857142857142855 .07763009 15.522564 1.1848537 .5729401 0
"TH:A" 2011 "Property & Construction" .5 .013262192 15.561353 1.1070081 .57702786 0
"TH:A" 2012 "Property & Construction" 0 .013741923 15.742103 1.2696354 .6365387 0
"TH:A" 2013 "Property & Construction" 0 .0015351704 16.00987 1.7140155 .6814458 0
"TH:A" 2014 "Property & Construction" 0 .0034536426 16.29612 1.858621 .7594991 0
"TH:AA" 1995 "Industrials" .3333333333333333 -.006353655 16.525984 4.846756 .6370975 1
"TH:AA" 1996 "Industrials" 0 -.0462963 16.797165 5.059855 .7687468 1
"TH:AA" 1997 "Industrials" .3333333333333333 -.17009 17.534548 2.606452 .8492652 1
"TH:AA" 1998 "Industrials" .4166666666666667 .11416897 17.54763 .7374102 .6734178 0
"TH:AA" 1999 "Industrials" .25 -.11794188 17.270618 2.397937 .8667688 1
"TH:AA" 2000 "Industrials" .5384615384615384 .019639796 17.28194 1.632345 .8497713 0
"TH:AA" 2001 "Industrials" .2222222222222222 .006626872 17.217733 1.587646 .8325074 0
"TH:AA" 2002 "Industrials" .35714285714285715 .04131401 17.18029 1.2312752 .7847582 0
"TH:AA" 2003 "Industrials" .375 .05050331 17.203983 2.1328473 .7387649 0
"TH:AA" 2004 "Industrials" .3333333333333333 .05501763 17.133413 1.411802 .6652893 0
"TH:AA" 2005 "Industrials" 0 .064267844 17.207062 1.1283801 .5871332 0
"TH:AA" 2006 "Industrials" .2 .065511316 17.220182 1.377417 .5249598 0
"TH:AA" 2007 "Industrials" .4444444444444444 .015064287 17.167637 1.3882604 .4864591 0
"TH:AA" 2008 "Industrials" .25 . . . . 0
"TH:AA" 2009 "Industrials" .4444444444444444 . . . . 0
"TH:AA" 2010 "Industrials" .3333333333333333 . . . . 0
"TH:AA" 2011 "Industrials" .14285714285714285 . . . . 0
"TH:AA" 2012 "Industrials" 0 . . . . 0
"TH:AA" 2013 "Industrials" 0 . . . . 0
"TH:AA" 2014 "Industrials" 0 . . . . 0
"TH:AAV" 1995 "Services" .23076923076923078 . . . . 0
"TH:AAV" 1996 "Services" .375 . . . . 0
"TH:AAV" 1997 "Services" .3333333333333333 . . . . 0
"TH:AAV" 1998 "Services" 0 . . . . 0
"TH:AAV" 1999 "Services" 0 . . . . 0
"TH:AAV" 2000 "Services" .4666666666666667 . . . . 0
"TH:AAV" 2001 "Services" 0 . . . . 0
"TH:AAV" 2002 "Services" .375 . . . . 0
"TH:AAV" 2003 "Services" 0 . . . . 0
"TH:AAV" 2004 "Services" .2 . . . . 0
"TH:AAV" 2005 "Services" .5 . . . . 0
"TH:AAV" 2006 "Services" 0 . . . . 0
"TH:AAV" 2007 "Services" .375 . . . . 0
"TH:AAV" 2008 "Services" .36363636363636365 . . . . 0
"TH:AAV" 2009 "Services" .3333333333333333 -.08246704 14.541677 . 3.183686 1
"TH:AAV" 2010 "Services" 0 .413217 15.397943 . 1.514293 0
"TH:AAV" 2011 "Services" 0 .53301877 15.147836 . 1.1440629 0
"TH:AAV" 2012 "Services" .3333333333333333 .473854 17.312746 .8970968 .20764913 0
"TH:AAV" 2013 "Services" .3333333333333333 .023205843 17.620733 .6654471 .4063622 0
"TH:AAV" 2014 "Services" .3333333333333333 .003700512 17.71752 .7719533 .4542441 0
"TH:ABICO" 1995 "Agro & Food Industry" .36363636363636365 . . . . 0
"TH:ABICO" 1996 "Agro & Food Industry" .3333333333333333 . . . . 0
"TH:ABICO" 1997 "Agro & Food Industry" .25 . . . . 0
"TH:ABICO" 1998 "Agro & Food Industry" .4444444444444444 . . . . 0
"TH:ABICO" 1999 "Agro & Food Industry" .23076923076923078 . . . . 0
"TH:ABICO" 2000 "Agro & Food Industry" .3333333333333333 -.4316369 14.122723 . 2.2422733 1
"TH:ABICO" 2001 "Agro & Food Industry" .2727272727272727 .2456064 14.19583 . 1.2081953 0
"TH:ABICO" 2002 "Agro & Food Industry" .36363636363636365 -.13187617 14.014474 . 1.4432036 1
"TH:ABICO" 2003 "Agro & Food Industry" 0 -.20122433 13.85465 . 1.7235887 1
"TH:ABICO" 2004 "Agro & Food Industry" .5 -1.2570164 13.76754 . 3.056561 1
"TH:ABICO" 2005 "Agro & Food Industry" .2 2.2142339 13.705672 . .929168 0
"TH:ABICO" 2006 "Agro & Food Industry" .3333333333333333 .04549691 13.680099 . .9444808 0
"TH:ABICO" 2007 "Agro & Food Industry" .45454545454545453 .14073876 13.111873 . 1.5902317 0
"TH:ABICO" 2008 "Agro & Food Industry" 0 -.07876977 12.94573 . 1.7910005 1
"TH:ABICO" 2009 "Agro & Food Industry" .3333333333333333 .11251536 13.14271 . 1.2879436 0
"TH:ABICO" 2010 "Agro & Food Industry" 0 .05981953 13.178632 . 1.1793016 0
"TH:ABICO" 2011 "Agro & Food Industry" 0 .1542739 13.224712 . .9512552 0
"TH:ABICO" 2012 "Agro & Food Industry" .3 .22630814 13.71115 . .5845832 0
"TH:ABICO" 2013 "Agro & Food Industry" .3 .1281038 13.741155 . .54510576 0
"TH:ABICO" 2014 "Agro & Food Industry" .3 .10894921 13.825327 . .4710184 0
end
format %ty Year
Solution 1:[1]
* Indicator variable for pre/post
gen post = .
replace post = 0 if inrange(Year,1999,2003)
replace post = 1 if inrange(Year,2010,2014)
* Separate regressions for each event period
regress y x1 x2 if post == 0
regress y x1 x2 if post == 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Cybernike |
