Here is a piece of code that loops thru every year and runs a regression for each individual year.
I would like to use a similar loop to run regressions over 2 different time windows (not year by year) where one time window is a subset of the total (1935-1950) and the other is the total (1935-1954). The two different periods are: i) all years less than 1951 -and- ii) all years less than 1955 (the last year in the data is 1954).
My code doesn't work because I don't know how to call the loop. (I am not great at loops.)
I would also like to label the end/last/final year used in the regression using outreg2 (which I know many giving help on here are not users of). I'm not sure how to do that. I feel year_x belongs in the label, but not sure?
Thanks in advance.
Code:
webuse grunfeld, clear set seed 06182021 forval i=1/5{ gen var`i'= runiformint(1,`i'0) } local i 0 levelsof year, local(years) foreach year of local years{ regress invest var1 var2 var3 var4 var5 if year==`year', vce(cluster company) local opt= cond(`i'==0, "replace", "append") outreg2 using myfile, `opt' ctitle( "`year'") excel local ++i }
My code doesn't work because I don't know how to call the loop. (I am not great at loops.)
I would also like to label the end/last/final year used in the regression using outreg2 (which I know many giving help on here are not users of). I'm not sure how to do that. I feel year_x belongs in the label, but not sure?
Code:
webuse grunfeld, clear set seed 06182021 forval i=1/5{ gen var`i'= runiformint(1,`i'0) } local i 0 local yearlist "1951 1955" forvalues year<year_x of local yearlist{ regress invest var1 var2 var3 var4 var5 , vce(cluster company) local opt= cond(`i'==0, "replace", "append") outreg2 using myfile, `opt' ctitle( "`year_x'") excel local ++i }
Comment