Hi statalisters,
I created a loop to convert all the variables of my dataset containing binary text values such as No/Yes into numeric variables with 0/1 and No/Yes labels. This is an example because I think the content of the variable is not important here.
I named the numeric counterpart just adding _bis to the original variable name.
Now, I would like to delete the original variables if their numeric counterpart (variable_bis) exists.
Here's what I tried:
The code returns an "invalid synthax".
I tried a bunch of things including adding double quotes around the first `var' after if, single quotes around "`var'"_bis or trying to create a local macro with variable names but I was not able to solve the problem.
I guess this is a matter of properly calling the variable name and not its content but I can't figure out the place of the single or double quotes.
Can somebody help please?
Best,
Maud
I created a loop to convert all the variables of my dataset containing binary text values such as No/Yes into numeric variables with 0/1 and No/Yes labels. This is an example because I think the content of the variable is not important here.
I named the numeric counterpart just adding _bis to the original variable name.
Now, I would like to delete the original variables if their numeric counterpart (variable_bis) exists.
Here's what I tried:
Code:
gen A=""
gen B=.
gen C=""
gen D=""
gen E=.
gen F="" ** this one contains text different from No/Yes so not converted in the loop
gen A_bis=.
gen C_bis=.
gen D_bis=.
foreach var of varlist A-F {
drop `var' if `var'=="`var'"_bis
}
I tried a bunch of things including adding double quotes around the first `var' after if, single quotes around "`var'"_bis or trying to create a local macro with variable names but I was not able to solve the problem.
I guess this is a matter of properly calling the variable name and not its content but I can't figure out the place of the single or double quotes.
Can somebody help please?
Best,
Maud

Comment