Hi All,
I currently have data that looks like the following:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(y x year)
23 2143 1980
23 431 1980
3 34 1980
23 134 1980
123 13 1981
12 4 1981
213 314 1981
123 31 1982
123 31 1982
12 4 1982
123 4 1982
123 4 1983
end
[/CODE]
Here, there is information on regressand y, and regressor x, by year. I wish to conduct regressions by decade. I have a panel of observations starting from 1850 onwards, so I want to conduct the regressions for 1850-1860, 1860-1870 and so on. The ultimate aim is to obtain predicted values for y, but based on coefficients that have been estimated by decade. The code I used in the past was to do this by year:
This however, estimates coefficients by year, which I need done by decade. One option is to group different decades by using the egen command with the group function, but I am at a loss at how to group by decade. Any suggestions are most welcome.
I currently have data that looks like the following:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(y x year)
23 2143 1980
23 431 1980
3 34 1980
23 134 1980
123 13 1981
12 4 1981
213 314 1981
123 31 1982
123 31 1982
12 4 1982
123 4 1982
123 4 1983
end
[/CODE]
Here, there is information on regressand y, and regressor x, by year. I wish to conduct regressions by decade. I have a panel of observations starting from 1850 onwards, so I want to conduct the regressions for 1850-1860, 1860-1870 and so on. The ultimate aim is to obtain predicted values for y, but based on coefficients that have been estimated by decade. The code I used in the past was to do this by year:
Code:
gen fitted=. levelsof year, local(levels) foreach i of local levels{ regress y x predict temp replace fitted=temp if year==`i' drop temp }
Comment