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
Transform a table: making options as variableDear all, I have this type of table: ID Date Culture ID Culture type Sample result 1 1 Jan 202…
Assuming ICCHello everyone, This is my first post here. I need icc for power calculation. I have outcome variabl…
optimization with STATAI am unfamiliar with STATA programming, and I am trying to program some very rudimentary optimizatio…
ivreg2 - despite using partial option I get full rank errorIn a multiple instrument regression using ivreg2 with gmm2s option I'm using partial. Despite using …
generate t-statHow can we modify this code to generate t-stat of the means instead of standard deviation (sd), and …
Subscribe to:
Post Comments (Atom)
0 Response to Split dataset for cross-validation
Post a Comment