hello all,
I'm just trying to break a large dataset into subdata sets, and save each of those data sets as separate files. Each of the subdata sets should include only the observations for each of a finite groups of one variable.
I'll reference the auto.dta dataset to keep things simple.
I'd like to create and save a dataset for each of the types of observations of the variable "foreign." One of the created files would have all of the observations for foreign vehicles, and another file would have all of the observations for domestic vehicles.
I'm trying this code (based on what I read here: https://www.stata.com/support/faqs/d...-with-foreach/)[INDENT=2]levelsof foreign, local(ForeignLevels)
foreach 1 of local ForeignLevels {
keep if foreign == `1'
save "D:\MyDocs\foreign_category_data_`ForeignLevel s'", replace
}[/INDENT]
Many of you already know that only one file is created and it only has the variable headers; no observations.
Two things before you answer:
-- yes, know that the value for "domestic" in the auto.dta is actually zero. I think that's beside the immediate point because in my actual data set, all of the values are 1 through 13.
-- I imagine that the problem is in the save command. Perhaps something to do with including the the local name.
I also imagine that there is simply an easier way to achieve my goal.
Thanks for any help you can provide!
I'm just trying to break a large dataset into subdata sets, and save each of those data sets as separate files. Each of the subdata sets should include only the observations for each of a finite groups of one variable.
I'll reference the auto.dta dataset to keep things simple.
I'd like to create and save a dataset for each of the types of observations of the variable "foreign." One of the created files would have all of the observations for foreign vehicles, and another file would have all of the observations for domestic vehicles.
I'm trying this code (based on what I read here: https://www.stata.com/support/faqs/d...-with-foreach/)[INDENT=2]levelsof foreign, local(ForeignLevels)
foreach 1 of local ForeignLevels {
keep if foreign == `1'
save "D:\MyDocs\foreign_category_data_`ForeignLevel s'", replace
}[/INDENT]
Many of you already know that only one file is created and it only has the variable headers; no observations.
Two things before you answer:
-- yes, know that the value for "domestic" in the auto.dta is actually zero. I think that's beside the immediate point because in my actual data set, all of the values are 1 through 13.
-- I imagine that the problem is in the save command. Perhaps something to do with including the the local name.
I also imagine that there is simply an easier way to achieve my goal.
Thanks for any help you can provide!
Comment