How to count the number of missing values in an observation/record/row
Dear sirs/madams,
My name is Anh. I am a student from Vietnam. I would like to calculate the number of missing values/entered values in a record.
I had a look at Epidata manual but I could not find any relevant instructions. Could you please help me with this problem?
Thank you so much,
Anh Dang
........................................................
Details of my problem:
My checklist contains 5 variables. Each variable is given a score (0,1,2), but in some records, a few variables are left blank because they are not relevant. The final score is calculated by dividing the sum of score of each variable (don't take the missing into account) by the 'total number of entered variables'. id var1 var2 var3 var4 var5 1 2 1 1 0 final score = (2+1+1+0)/4 ( I use the command 'ignoremissing' to get the sum) 2 2 2 2 1 1 final score = (2+2+2+1+1)/5 3 1 1 final score=(1+1)/2
I assume you are doing this in Analysis. The solution is similar for a .chk file, but the syntax is different. It is also a bit tricky doing this in a .chk file because values can be changed after the calculation is done if you are not careful.
* c is count of nonmissing variables * s is sum of nonmissing variables * score is final score (average of nonmissing variables)
gen c=0 gen s=0 if var1 <> . then c=c+1 if var1 <> . then s=s+var1 if var2 <> . then c=c+1 if var2 <> . then s=s+var2 if var3 <> . then c=c+1 if var3 <> . then s=s+var3 if var4 <> . then c=c+1 if var4 <> . then s=s+var4 if var5 <> . then c=c+1 if var5 <> . then s=s+var5 gen score = s/c
if you do not have any defined missing values, you can also calculate c this way:
c = 5mv(var1)mv(var2)mv(var3)mv(var4)mv(var5)
and you can also calculate s this way:
s=iif(var1<>. , var1,0)+iif(var2<>. , var2,0)+iif(var3<>. , var3,0)+iif(var4<>. , var4,0)+iif(var5<>. , var5,0)
Check the help for these functions to see how they work: mv() and iif()
Jamie
On 20130613, at 3:39 AM, epidatalist@lists.umanitoba.ca wrote:
Details of my problem:
My checklist contains 5 variables. Each variable is given a score (0,1,2), but in some records, a few variables are left blank because they are not relevant. The final score is calculated by dividing the sum of score of each variable (don't take the missing into account) by the 'total number of entered variables'. id var1 var2 var3 var4 var5 1 2 1 1 0 final score = (2+1+1+0)/4 ( I use the command 'ignoremissing' to get the sum) 2 2 2 2 1 1 final score = (2+2+2+1+1)/5 3 1 1 final score=(1+1)/2
participants (1)

epidatalist＠lists.umanitoba.ca