Announcement

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

  • Retrieve the numeric value of a label

    I have a string variable nation2 distributed as follows:

    Code:
    
    . tab nation2, m
    
        nation2 |      Freq.     Percent        Cum.
    ------------+-----------------------------------
                |     51,292       16.10       16.10
          OTHER |    212,447       66.68       82.78
             SE |     54,854       17.22      100.00
    ------------+-----------------------------------
          Total |    318,593      100.00
    Now I encode it in a numeric variable to be used in a regression model

    Code:
    encode nation2, gen(nation_encoded)

    Code:
    . tab nation_encoded, nolab m
    
    nation_enco |
            ded |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |    212,447       66.68       66.68
              2 |     54,854       17.22       83.90
              . |     51,292       16.10      100.00
    ------------+-----------------------------------
          Total |    318,593      100.00

    Now I want to count the instances of nation_encoded=="OTHER".

    If I do

    Code:
    . count if nation_encoded=="OTHER"
    type mismatch
    I have to do

    Code:
    .  count if nation_encoded==1
      212,447
    How can I use the command with the label, not with the numeric value?

    Is there something like

    Code:
    count if nation_encoded==nation_encoded.labels.OTHER
    ?

  • #2
    Code:
    count if nation_encoded=="OTHER":nation_encoded
    Where the second use of nation_encoded is the name of the value label, automatically defined as nation_encoded when you use -encode-.

    Comment

    Working...
    X