Hello,
I have a data set that contains observations from two different cities. I would like to split the dataset into two, with observations from each city in a separate dataset. I would prefer to do this at the end of a do file that will define the variables in the dataset, as each city has the same variables.
I have tried using foreach, where 111 and 112 are the individual city codes:
foreach x in varlist 111 112 {;
saveold "`data'_`x'_rds.dta", version(12) replace;
};
However, that just saves the same dataset twice under a different name.
I have also tried using an "if" option with save ( saveold "`data'_111_rds.dta" if city==111, version(12) replace
but that is not allowed.
I can find plenty of information on how to merge datasets but not so much on splitting them so any advice is very welcome!
Thank you in advance,
Sarah
I have a data set that contains observations from two different cities. I would like to split the dataset into two, with observations from each city in a separate dataset. I would prefer to do this at the end of a do file that will define the variables in the dataset, as each city has the same variables.
I have tried using foreach, where 111 and 112 are the individual city codes:
foreach x in varlist 111 112 {;
saveold "`data'_`x'_rds.dta", version(12) replace;
};
However, that just saves the same dataset twice under a different name.
I have also tried using an "if" option with save ( saveold "`data'_111_rds.dta" if city==111, version(12) replace

I can find plenty of information on how to merge datasets but not so much on splitting them so any advice is very welcome!
Thank you in advance,
Sarah
Comment