Hello
I'm trying to see different methods for coding. And I would like to verify with the experts in the field.
So, here are two methods and two outputs. The output shows different results. To me, both codings seem correct. But, I would like to have an expert opinion. Thank you so much.
Method 1
gen diff_fundistest=.
replace diff_fundistest=0 if (newdiffhear==0 & newdiffsee==0 & newdiffthink==0 & newdiffwalk==0 & newdiffdress==0 & newdifferand==0)
replace diff_fundistest=1 if (newdiffhear==1 | newdiffsee==1 | newdiffthink==1 | newdiffwalk==1 | newdiffdress==1 | newdifferand==1)
label define diff_fundistest 1 "Yes" 0 "No"
label value diff_fundistest diff_fundistest
label variable diff_fundistest "diff_fundistest"
tab diff_fundistest
output of method 1
tab diff_fundistest
diff_funcdis_ Freq. Percent Cum.
------------+-----------------------------------
No | 201,715 79.22 79.22
Yes | 52,896 20.78 100.00
------------+-----------------------------------
Total | 254,611 100.00
Method2
gen diff_fundistest2=.
replace diff_fundistest2=0 if (newdiffhear==0 & newdiffsee==0 & newdiffthink==0 & newdiffwalk==0 & newdiffdress==0 & newdifferand==0)
replace diff_fundistest2=1 if (newdiffhear==1 & newdiffsee==0 & newdiffthink==0 & newdiffwalk==0 & newdiffdress==0 & newdifferand==0)
replace diff_fundistest2=1 if (newdiffhear==0 & newdiffsee==1 & newdiffthink==0 & newdiffwalk==0 & newdiffdress==0 & newdifferand==0)
replace diff_fundistest2=1 if (newdiffhear==0 & newdiffsee==0 & newdiffthink==1 & newdiffwalk==0 & newdiffdress==0 & newdifferand==0)
replace diff_fundistest2=1 if (newdiffhear==0 & newdiffsee==0 & newdiffthink==0 & newdiffwalk==1 & newdiffdress==0 & newdifferand==0)
replace diff_fundistest2=1 if (newdiffhear==0 & newdiffsee==0 & newdiffthink==0 & newdiffwalk==0 & newdiffdress==1 & newdifferand==0)
replace diff_fundistest2=1 if (newdiffhear==0 & newdiffsee==0 & newdiffthink==0 & newdiffwalk==0 & newdiffdress==0 & newdifferand==1)
label define diff_fundistest2 1 "Yes" 0 "No"
label value diff_fundistest2 diff_fundistest2
label variable diff_fundistest2 "diff_fundistest2?"
tab diff_fundistest2
output of method 2
diff_fundis2 Freq. Percent Cum.
------------+-----------------------------------
No | 201,715 87.23 87.23
Yes | 29,529 12.77 100.00
------------+-----------------------------------
Total | 231,244 100.00
I'm trying to see different methods for coding. And I would like to verify with the experts in the field.
So, here are two methods and two outputs. The output shows different results. To me, both codings seem correct. But, I would like to have an expert opinion. Thank you so much.
Method 1
gen diff_fundistest=.
replace diff_fundistest=0 if (newdiffhear==0 & newdiffsee==0 & newdiffthink==0 & newdiffwalk==0 & newdiffdress==0 & newdifferand==0)
replace diff_fundistest=1 if (newdiffhear==1 | newdiffsee==1 | newdiffthink==1 | newdiffwalk==1 | newdiffdress==1 | newdifferand==1)
label define diff_fundistest 1 "Yes" 0 "No"
label value diff_fundistest diff_fundistest
label variable diff_fundistest "diff_fundistest"
tab diff_fundistest
output of method 1
tab diff_fundistest
diff_funcdis_ Freq. Percent Cum.
------------+-----------------------------------
No | 201,715 79.22 79.22
Yes | 52,896 20.78 100.00
------------+-----------------------------------
Total | 254,611 100.00
Method2
gen diff_fundistest2=.
replace diff_fundistest2=0 if (newdiffhear==0 & newdiffsee==0 & newdiffthink==0 & newdiffwalk==0 & newdiffdress==0 & newdifferand==0)
replace diff_fundistest2=1 if (newdiffhear==1 & newdiffsee==0 & newdiffthink==0 & newdiffwalk==0 & newdiffdress==0 & newdifferand==0)
replace diff_fundistest2=1 if (newdiffhear==0 & newdiffsee==1 & newdiffthink==0 & newdiffwalk==0 & newdiffdress==0 & newdifferand==0)
replace diff_fundistest2=1 if (newdiffhear==0 & newdiffsee==0 & newdiffthink==1 & newdiffwalk==0 & newdiffdress==0 & newdifferand==0)
replace diff_fundistest2=1 if (newdiffhear==0 & newdiffsee==0 & newdiffthink==0 & newdiffwalk==1 & newdiffdress==0 & newdifferand==0)
replace diff_fundistest2=1 if (newdiffhear==0 & newdiffsee==0 & newdiffthink==0 & newdiffwalk==0 & newdiffdress==1 & newdifferand==0)
replace diff_fundistest2=1 if (newdiffhear==0 & newdiffsee==0 & newdiffthink==0 & newdiffwalk==0 & newdiffdress==0 & newdifferand==1)
label define diff_fundistest2 1 "Yes" 0 "No"
label value diff_fundistest2 diff_fundistest2
label variable diff_fundistest2 "diff_fundistest2?"
tab diff_fundistest2
output of method 2
diff_fundis2 Freq. Percent Cum.
------------+-----------------------------------
No | 201,715 87.23 87.23
Yes | 29,529 12.77 100.00
------------+-----------------------------------
Total | 231,244 100.00

Comment