Hello,
I have been trying to create a new variable called truemiss to see whether or not ALL the variables in the dataset have missing values. There are 45 variables in the dataset. I first assigned zero to truemiss. Then I used loop to go through each variable, and assign zero to truemiss if the variable is missing (indicated by "") ; otherwise, assign 1 to the truemiss. Last, I attempted to add up the values of truemiss. Below are my codes. For an unknown reason, it is not working. I wondered how to solve this problem? I cannot figure it out.
Many thanks,
David
I have been trying to create a new variable called truemiss to see whether or not ALL the variables in the dataset have missing values. There are 45 variables in the dataset. I first assigned zero to truemiss. Then I used loop to go through each variable, and assign zero to truemiss if the variable is missing (indicated by "") ; otherwise, assign 1 to the truemiss. Last, I attempted to add up the values of truemiss. Below are my codes. For an unknown reason, it is not working. I wondered how to solve this problem? I cannot figure it out.
Code:
gen truemiss=0
foreach bimiss of varlist var1-var45 {
recode truemiss=0 if (`bimiss'=="")
recode truemiss=1 if (`bimiss'!="")
sum(truemiss)
}
Many thanks,
David

Comment