Dear all,
I'm using DHS surveys and I'd like to create a loop to select the same variables from different files (surveys) and append them in one new dataset. STATA doesn't point out any errors but the final dataset is not correct as variables don't match (i.e Brazil's region attributed with Kabul). Also I intended to create a PCA score for each country based on these variables. Here is my code:
Thank you,
Best.
I'm using DHS surveys and I'd like to create a loop to select the same variables from different files (surveys) and append them in one new dataset. STATA doesn't point out any errors but the final dataset is not correct as variables don't match (i.e Brazil's region attributed with Kabul). Also I intended to create a PCA score for each country based on these variables. Here is my code:
Code:
local files : dir . files "*.dta" tempfile nfile save `nfile', emptyok foreach f of local files { use `"`f'"', clear keep hv000 hv007 hv024 sort hv000 hv007 hv024 pca hv000 hv007 hv024 , comp(2) covariance append using `nfile' save `"`nfile'"', replace } label data "jj, long format" save `"`dir1'jj.dta"', replace
Best.
Comment