Dear all,
I'm trying to run an out-of-sample forecast in Stata using the forvalue command. I have a total of 17 years in my data file.
I first run an in-sample regression and predict.
I then want to run a regressions for all years in the sample while always excluding one year from it. I do that in the following way:
My question is how to run the -predict- command after every regression in the loop and store the prediction for electionID!=i to the corresponding electionID.
As an example I want to run
and then use this model to -predict- the share for electionID=2. Then do this for all years in my sample.
Here's an example of my data:
Thank you very much in advance!
I'm trying to run an out-of-sample forecast in Stata using the forvalue command. I have a total of 17 years in my data file.
I first run an in-sample regression and predict.
Code:
reg share share_lagged1 poll incumbent predict p_insample
Code:
forval i = 1/17 { regress share share_lagged1 poll incumbent if electionID!=`i' }
As an example I want to run
Code:
reg share share_lagged1 poll incumbent if electionID != 2
Here's an example of my data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input year electionID share share_lagged1 poll incumbent 2012 16 26.299999237060547 34.599998474121094 31 0 2012 16 8.600000381469727 6.699999809265137 4 0 2012 16 11.300000190734863 12.100000381469727 17 1 2012 16 2.5 5.599999904632568 5 0 2012 16 39.099998474121094 34.5 34 1 2017 17 . 26.299999237060547 32 0 2017 17 . 8.600000381469727 7 0 2017 17 . 11.300000190734863 12 1 2017 17 . 2.5 5 0 2017 17 . 39.099998474121094 32 1 end
Thank you very much in advance!
Comment