Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Different coding methods

    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

  • #2
    We assume that your newdiffhear newdiffsee newdiffthink newdiffwalk newdiffdress and newdifferand all have a value of either 0 or 1 with no missing values.

    In method 2, any observation with more than one variable with a value of 1 will have a missing value for _fundistest2.

    In method 1, given the assumptions in the first paragraph,
    Code:
    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)
    can be shortened to
    Code:
    gen diff_fundistest = max(newdiffhear, newdiffsee, newdiffthink, newdiffwalk, newdiffdress, newdifferand)

    Comment


    • #3
      Thank you, Dr. Lisowski. It helps. I appreciate your explanation.

      Comment

      Working...
      X