Announcement

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

  • Exclude missing values in tabulation

    Hi Everyone

    I am trying tabulate the frequency and percentage for the values 1 and 2. I dont want to include the missing values NA in the tabulation and want to also label 1 as "home" and 2 as "away". I would appreciate help on how to code it, thank you!

    ---------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str2 Q01
    "1" 
    "1" 
    "NA"
    "1" 
    "1" 
    "1" 
    "NA"
    "1" 
    "1" 
    "NA"
    "NA"
    "1" 
    "1" 
    "1" 
    "1" 
    "1" 
    "1" 
    "1" 
    "1" 
    "1" 
    "1" 
    "1" 
    "1" 
    "1" 
    "1" 
    "1" 
    "NA"
    "1" 
    "1" 
    "NA"
    "1" 
    "NA"
    "1" 
    "NA"
    "1" 
    "1" 
    "1" 
    "NA"
    "1" 
    "NA"
    "2" 
    "2" 
    "2" 
    "2" 
    "1" 
    "NA"
    "2" 
    end
    ------------------ copy up to and including the previous line ------------------


  • #2
    To do anything useful with this variable in Stata, you will want to convert it from a string value to a numeric value.
    Code:
    replace Q01 = "." if Q01=="NA"
    destring Q01, replace
    label define Q01L 1 "Home" 2 "Away" 
    label values Q01 Q01L
    Code:
    . tab Q01
    
            Q01 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
           Home |         31       86.11       86.11
           Away |          5       13.89      100.00
    ------------+-----------------------------------
          Total |         36      100.00
    
    . tab Q01, missing
    
            Q01 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
           Home |         31       65.96       65.96
           Away |          5       10.64       76.60
              . |         11       23.40      100.00
    ------------+-----------------------------------
          Total |         47      100.00
    
    . tab Q01, missing nolabel
    
            Q01 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |         31       65.96       65.96
              2 |          5       10.64       76.60
              . |         11       23.40      100.00
    ------------+-----------------------------------
          Total |         47      100.00

    Comment

    Working...
    X