I have got a large dataset available which has 14 yearly datapoints for several independent variables available for a large number of firms.
I am trying to build a code which loops a number of regressions for a firm. Please see attached a data file which has the variables for two firms.
Precisely, I want the code to regress the data from t-14 until and including t-5 to forecast t+5 (In the dataset the time is given without the 't', as I couldn't find how to add this). In all of these regressions, the dependent variable is E_Next_T and all the independent variables are NegE, E, NegE_Times_E, B and TACC.
Then I want the code to regress the data from t-13 until and including t-4 to forecast t+4, regress t-12 until and including t-3 to forecast t+3, regress t-11 until and including t-2 to forecast t+2, regress t-10 until and including t-1 to forecast t+1.
This way I will find a wide number of outcomes for each independent variable, and I would like Stata to store every factor obtained from the regressions for every independent variable for T+1, t+2, t+3, t+4 and t+5 (I need them later to backtest whether E_Next_T is similar to the real values). So, I need to store the independent variables obtained from the regressions and their p-values in vectors.
Then, I want Stata to do this exact same process for every firm.
Could anyone please help me? I've provided a sample data set here:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(Time Firm NegE E NegE_Times_E B TACC E_Next_T group) -14 1 0 -50 0 4000 234 200 1 -13 1 1 200 200 4000 452 -40 1 -12 1 0 -40 0 4200 534 400 1 -11 1 1 400 400 4200 123 300 1 -10 1 1 300 300 4200 342 -10 1 -9 1 0 -10 0 4200 454 430 1 -8 1 1 430 430 4200 235 520 1 -7 1 1 520 520 4200 672 -20 1 -6 1 0 -20 0 3900 312 420 1 -5 1 1 420 420 3900 213 350 1 -4 1 1 350 350 3900 673 230 1 -3 1 1 230 230 4000 456 300 1 -2 1 1 300 300 4000 345 240 1 -1 1 1 240 240 4000 734 345 1 -14 2 0 -40 0 7000 741 340 2 -13 2 1 340 340 7000 734 560 2 -12 2 1 560 560 7000 236 700 2 -11 2 1 700 700 7000 452 800 2 -10 2 1 800 800 7000 752 -25 2 -9 2 0 -25 0 7000 348 300 2 -8 2 1 300 300 7000 742 350 2 -7 2 1 350 350 7000 345 360 2 -6 2 1 360 360 7400 435 400 2 -5 2 1 400 400 7400 345 450 2 -4 2 1 450 450 7400 673 430 2 -3 2 1 430 430 7400 634 470 2 -2 2 1 470 470 7400 237 500 2 -1 2 1 500 500 7400 732 470 2 end
0 Response to Running regressions in a loop
Post a Comment