Announcement

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

  • labeling a variable

    Dear all,

    There is a string variable: cod_fluxo

    I am going to show this variable in this way. First dedicating value 1= IMPORTS and 2 =EXPORTS. I mean instead of 1 and 2 I need to be shown as IMPORTS & EXPORTS.
    Second, labeling IMPORTS as 2 and EXPORTS as 1.
    Because the rest of the raw data are classified in a way that 1 is responsible for exports and number 2 for imports. But the new raw data classification is the other way around. So I have to modify this one in order to match with the rest.

    Code:
    input str3 cod_fluxo
    "1"
    "1"
    "1"
    "1"
    "1"
    "1"
    "1"
    "1"
    "1"
    "2"
    "1"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "1"
    "1"
    "1"
    "1"
    "1"
    "1"
    "1"
    "1"
    "1"
    "1"
    "1"
    "2"
    "1"
    "1"
    "1
    "1"
    "2"
    "1"
    "1"
    "2"
    "2"
    "1"
    "2"
    "1"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "1"
    "1"
    "1"
    "2"
    "2"
    "2"
    "2"
    "1"
    "1"
    "1"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "1"
    "1"
    "1"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "2"
    "1"
    "1"
    "1"
    "1"
    "2"
    "1"
    "1"
    "1"
    "1"
    "1"
    "2"
    end
    Any ideas appreciated.

    Cheers,

    Paris

  • #2
    I think it's somewhat dangerous to flip the coding this way between 1 and 2 under a very generic name. I'd suggest the more typical 1 and 0, where 1 indicates a "yes" and 0 indicates a "no". And give these yes/no a context through the variable name.

    E.g.

    Code:
    clear
    input str3 cod_fluxo
    "1"
    "2"
    ""
    end
    
    gen import = (cod_fluxo == "1") if !missing(cod_fluxo)
    gen export = (cod_fluxo == "2") if !missing(cod_fluxo)
    
    * Optionally, also add label scheme
    label define l_im 1 "Import" 0 "Export"
    label define l_ex 0 "Import" 1 "Export"
    label values import l_im
    label values export l_ex
    If you create this export/import indicator for every data set, then no matter how yo append them, they will still make sense.

    Comment


    • #3
      Dear ken,
      Thank you so much for getting back to me.
      You are right. It worked perfectly.

      Comment


      • #4
        I agree with @Ken Chui: There are many advantages in coding a binary (*) variable as 0 and 1 and no real disadvantages.

        For a survey see https://journals.sagepub.com/doi/pdf...36867X19830921

        (*) attribute, Boolean, dichotomous, dummy, indicator, logical, quantal

        Comment

        Working...
        X