Hi all!
I need to split my dataset into 10 folds to do cross-validation "manually" (I know about the crossfold command, but it won't work for what I need).
I need a loop that allows me to run 10 cycles. In each of them, I need to select the train set (9 parts) and the validation dataset (1 part). Then I will run my model is the trainset and use the predict command to estimate the prediction of this model on the validation dataset.
This is what I have come up with so far, which I am aware it's wrong...
sysuse auto, clear
generate prp=0
* ** variable with the fold number. I know that in R there is a command that allows me to split n observations into K groups to be used for (repeated) K-fold cross-validation (cvfolds). Any suggestion?
egen split = seq(), f(1) t(10)
forvalues i = 1/10{
reg price mpg headroom if split != `i'
predict p if split =`i'
replace prp=p
drop p
}
Thanks a lot in advance!
Related Posts with Split dataset for cross-validation
Can 'dsge' command be a simpler alternative to 'sspace' for natural interest rate estimation?Hi I’m grad student on Economics but basically I’m an idiot if it comes to econometrics software or …
Is it possible to make the Hausman specification test by comparing two-way error component models?Good morning. I would like to know if the comparison between the two-way effect random effects compo…
Storing estimated coefficients in a loopHello everyone, I am working on a dataset containing daily stock returns of more than 3000 firms a…
Programming minimum distance estimator using optimizeI'm trying to program up a minimum distance estimator for a structural model that attempts to match …
IpfrakingI'm using Ipfraking to generate weights for my survey data. For some reason when the iteration fini…
Subscribe to:
Post Comments (Atom)
0 Response to Split dataset for cross-validation
Post a Comment