Dear Statalist members,
I am trying to run my regression through 2 loops. I want to run a regression for j = SAMPLE_60_1 until SAMPLE_60_10 (a dummy variable) and i for Halfyear == 13 until Halfyear == 33 (denoting the halfyear subsample).
I run a regression for each half year on a part of sample (when SAMPLE_60_`j' equals 1) and use it to forecast the remainder of the data (when SAMPLE_60_`j' equals 0). I regress the forecasted values on the observed dependent variable and save this in a file using outreg2.
I expect the ouput to be like this:
However, it only calculates HY13S1 and HY14S1 and then stoppes as all variables in the regression for HY14S1 are omitted. However, I thought by using
I step around this problem.
Simplified code
Actual code
Thanks in advance for your time!
I am trying to run my regression through 2 loops. I want to run a regression for j = SAMPLE_60_1 until SAMPLE_60_10 (a dummy variable) and i for Halfyear == 13 until Halfyear == 33 (denoting the halfyear subsample).
I run a regression for each half year on a part of sample (when SAMPLE_60_`j' equals 1) and use it to forecast the remainder of the data (when SAMPLE_60_`j' equals 0). I regress the forecasted values on the observed dependent variable and save this in a file using outreg2.
I expect the ouput to be like this:
HY13S1 | HY14S1 | HY15S1 | HY16S1 | HY17S1 | HY18S1 | HY13S1 | HY13S2 | .... | |
COEFF | |||||||||
... |
Code:
capture
My question: Do correctly loop using forvalues?
Simplified code
Code:
forvalues j = 1/10 { forvalues i = 13/18 { capture xtreg DEP IDEP1 IDEP2 IDEP3 i.Year, fe if Halfyear==`i' & SAMPLE_60_`j' == 1 capture predict HY`i'_fcst_B`j' if Halfyear==`i' & SAMPLE_60_`j' == 0, xb capture xtreg HY`i'_fcst_B`j' DEP capture outreg2 using doc, append } }
Actual code
Code:
forvalues j = 1/3 { forvalues i = 13/18 { capture quietly xtreg W_l_G_Spread L(1).W_l_G_Spread L(0/1).W_l_LiqM L(0/1).W_l_Price_Equity L(0).W_l_EvolM L(0/2).W_l_brent i.Year, fe if Halfyear==`i' & SAMPLE_60_`j' == 1 capture quietly predict HY`i'_fcst_B`j' if Halfyear==`i' & SAMPLE_60_`j' == 0, xb capture quietly xtreg HY`i'_fcst_B`j' W_l_G_Spread capture quietly outreg2 using E_S60_HF_M1A, append dec(3) ctitle(HF`i'S`j') } }
Thanks in advance for your time!
Comment