Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65574

Loop only through string variables from my variable list

$
0
0
Hi

I have two almost identical datasets. I want to find any discrepancies between the variables. I have merged the two datasets. I therefore have 100 variables named var1 to var100. Then I have 100 more that are named var1_temp, var2_temp - var100_temp (from the second dataset). I also have other variables that I do not want to be part of this loop (for instance the variable on which I have merged the two datasets). I have written the following code, but am struggling to work out how to specify that from my variables var1-var100 I want to replace with "" for strings and with . for numeric.

foreach var of varlist var1-var100{
gen x`var'=1 if `var'!=`var'_temp /*to show up if the two variables are not identical*/
replace x`var'="" if `var'_temp=="" /*only want to do this for the string variables*/
replace x`var'=. if `var'_temp==. /*only want to do this for the numeric variables*/
dropmiss x`var', force /*drop the variables where all are missing*/
}

Any help would be appreciated!
Thanks

Viewing all articles
Browse latest Browse all 65574

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>