Code:
Example generated by -dataex-. To install: ssc install dataex clear input str6 date int id float(volatility return Time) "Jan-91" 1 .0076515 .0080953 . "Jan-91" 2 .0082569 .0050203 . "Jan-91" 3 .0116118 -.110187 . "Jan-91" 4 .007547 .0189273 . "Jan-91" 12 .0085447 .0023504 . "Jan-91" 13 .0088329 .0281606 . "Jan-91" 17 .010967 -.0018181 . "Jan-91" 25 .0093389 .00644 . "Jan-91" 26 .0088709 -.0155422 . "Jan-91" 27 .011748 .0205174 . "Jan-91" 28 .0098117 .0048176 . "Jan-91" 29 .0108828 -.005227 . "Jan-91" 30 .0100979 -.0044575 . "Jan-91" 31 .0143006 .0110809 . "Jan-91" 40 .0101437 -.0458095 . "Feb-91" 106 .0142047 .1218685 . "Feb-91" 107 .0033309 .0998751 . "Feb-91" 109 .0070853 .1022816 . "Feb-91" 112 .0020066 .1269131 . "Feb-91" 116 .0081126 .0239336 . "Feb-91" 117 .0027221 .1054625 . "Feb-91" 118 .007132 .0922486 . "Feb-91" 119 .0037425 .111814 . "Feb-91" 123 .0041721 .1069812 . "Feb-91" 124 .021932 .1650661 . "Feb-91" 125 .005186 .1086161 . "Feb-91" 126 .0051869 .1417216 . "Feb-91" 209 .0088042 .0898837 . "Feb-91" 212 .008878 .0804817 . "Feb-91" 213 .0033121 .1345911 . "Feb-91" 214 .0130733 .1257204 . "Feb-91" 215 .0079939 .1178345 . "Feb-91" 216 .0040007 .0999595 . "Feb-91" 217 .0068929 .1253842 . end format %tmCCYY!mNN Time
I want to do a cross-sectional (id) regression for each month. The regression model: return(t)=a+b*volatility(t-1)+c
I also need to do a loop, as I have 268 month
Then, I also need to predict the value of b(coefficient) for each month, and the t-statistic and p-value of coefficient for each month.
finally, I need to calculate the mean of b as well as t-statistic. "(b1+b2+...+b268)/268" the average value is easy to do, but the t-statistic of the mean value of b is not. I am thinking whether STATA can calculate the t-statistic or not? otherwise, I have to calculate manually.
I try to write the code:
gen time = monthly(date, "M19Y")
format time %tm
tsset id time
egen group=group(time)
forvalue i=1(1)268 {
reg return L.volatility i.month if group ==`i'
predict ???
}
many thanks Clyde Schechter for previous help. but the regression code doesn't work and I have no idea how to predict coefficient, especially the t-statistic and p-value.
I am really appreciate if someone could help me to figure out the code.
Many thanks again!!!
Comment