Announcement

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

  • Computing the percent of variable

    Dear Profs and colleagues,

    I have two variables, 'nacio' and 'S_lp_iv_normalized,' where the latter can be either 0 or non-zero. I'm going to compute what percentage of 'nacio' is not PT when 'S_lp_iv_normalized' is non-zero.
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str6 nacio float S_lp_iv_normalized
    "PT"         0
    "PT"         0
    "PT"         0
    "CN"   .0197452
    "NP"    .0205642
    "CN"    .0197452
    "CN"    .0197452
    "NP"    .0205642
    "NP"    .0205642
    "CN"    .0197452
    "NP"    .0205642
    "NP"    .0205642
    "CN"    .0197452
    "PT"         0
    "PT"         0
    "PT"         0
    "PT"         0
    "PT"         0
    "MZ"   .0495451
    "PT"         0
    "PT"         0
    "PT"         0
    "PT"         0
    "PT"         0
    "PT"         0
    "UA" .12228884
    "UA" .12228884
    "PT"         0
    "PT"         0
    "PT"         0
    "PT"         0
    "UA" .12228884
    end
    Any ideas are appreciated.

    Cheers,
    Paris

  • #2
    This is one way, although in your example data, all non-PT cases have a non-zero value of the other variable.

    Code:
    gen byte nacio_pt = nacio=="PT"
    label define pt 0 "Not PT" 1 "PT", modify
    label values nacio_pt pt
    tab nacio_pt if S_lp_iv_normalized > 0 & !mi(S_lp_iv_normalized)

    Comment


    • #3
      Dear Leonardo, Thank you for getting back to me.
      It works !

      Comment

      Working...
      X