Announcement

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

  • RECODE help

    I have a variable that states the name of the assurance provider called NewNumVerifiers. Originally, this was a string variable, but, I codified it into a numerical variable. Here is a sample:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte NewNumVerifiers
    15
     0
    38
    20
    20
    20
     3
     3
     3
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
    23
    15
     0
    15
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
    38
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
    15
    15
    15
    15
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
    end
    label values NewNumVerifiers NewNumVerifiers
    label def NewNumVerifiers 0 "None", modify
    label def NewNumVerifiers 3 "Bureau Veritas Certification", modify
    label def NewNumVerifiers 15 "ERM", modify
    label def NewNumVerifiers 20 "ISOS Group LLC", modify
    label def NewNumVerifiers 23 "Jane Nelson (Ms)", modify
    label def NewNumVerifiers 38 "Trucost", modify



    I have the following two questions:

    1. How can I recode the variable called NewNumVerifiers into two categories: 0 "None" (in the original variable) as the same in the new variable called AssuredOrNot, &, everything else (in the original variable) as 1 in the new variable called AssuredOrNot?

    2. How can I recode the new variable called AssuredOrNot into two categories: 13 "Deloitte & Touche", 16 "Ernst & Young", 24 "KPMG LLP", 29 "Moss Adams LLP", 30 "PriceWaterhouseCoopers" (all in the variable called AssuredOrNot) as 1 in another new variable called AuditFirm, &, everything else (in the variable AssuredOrNot) as 0 in the new variable called AuditFirm?

    3. What am I doing wrong with the following code?

    Here is the code that I used:

    recode NewNumVerifiers (0=0 "Not Assured") (*=1 "Assured"), gen(AssuredOrNot) label(Assured or Not)


    I would be really grateful for your help! Thank you!

  • #2
    I am thinking that you misunderstood the meaning of the "label" option on the recode command. What it provides is a name for the value label you created for the new variable. I think you thought it would provide a variable label to replace the ugly variable label created by recode.
    Code:
    . recode NewNumVerifiers (0=0 "Not Assured") (*=1 "Assured"), gen(AssuredOrNot)
    (16 differences between NewNumVerifiers and AssuredOrNot)
    
    . describe AssuredOrNot
    
    Variable      Storage   Display    Value
        name         type    format    label      Variable label
    ------------------------------------------------------------------------------------------------
    AssuredOrNot    byte    %11.0g     AssuredOrNot
                                                  RECODE of NewNumVerifiers
    
    . tab AssuredOrNot
    
      RECODE of |
    NewNumVerif |
           iers |      Freq.     Percent        Cum.
    ------------+-----------------------------------
    Not Assured |         84       84.00       84.00
        Assured |         16       16.00      100.00
    ------------+-----------------------------------
          Total |        100      100.00
    
    . label variable AssuredOrNot "Assured or Not"
    
    . tab AssuredOrNot
    
     Assured or |
            Not |      Freq.     Percent        Cum.
    ------------+-----------------------------------
    Not Assured |         84       84.00       84.00
        Assured |         16       16.00      100.00
    ------------+-----------------------------------
          Total |        100      100.00
    As for your second question, you don't want to recode AssuredOrNot, which only takes two values. You again want to recode NewNumVerifiers in a manner similar to what you have already done.
    Code:
    recode NewNumVerifiers (13 16 24 29 30 = 1 "Audit Firm") (* = 0 "Not Audit Firm"), generate(AuditFirm)
    label variable AuditFirm "Audit Firm"
    Last edited by William Lisowski; 13 Feb 2022, 19:40.

    Comment


    • #3
      Dear Prof. Lisowski,

      Thank you very much for your help. I greatly appreciate your quick response!

      Comment


      • #4
        I do have the following question:

        I already have a 0 (zero in my original var NewNumVerifiers), which means that these companies/observations have no assurance provider - I want to exclude them from the AuditFirm varible. The remaining companies/observations should classified as "Audit Firm" and "Not Audit Firm."

        Is this possible?

        Comment


        • #5
          Code:
           
           recode NewNumVerifiers (13 16 24 29 30 = 1 "Audit Firm") (0 = -1 "Not Applicable") (* = 0 "Not Audit Firm"), generate(AuditFirm) label variable AuditFirm "Audit Firm"
          Alternatively, you could replace -1 with . if you want them coded as missing

          Comment


          • #6
            I changed 5 observations of NewNumVerifiers from 0 to 13 16 24 29 30 so there would be audit firms in the example data. Then I recode the 0 NewNumVerifiers to a Stata missing value - I think that is what you mean by "exclude them".
            Code:
             recode NewNumVerifiers (0=0 "Not Assured") (*=1 "Assured"), gen(AssuredOrNot)
            (21 differences between NewNumVerifiers and AssuredOrNot)
            
            . label variable AssuredOrNot "Assured or Not"
            
            . tab AssuredOrNot
            
             Assured or |
                    Not |      Freq.     Percent        Cum.
            ------------+-----------------------------------
            Not Assured |         79       79.00       79.00
                Assured |         21       21.00      100.00
            ------------+-----------------------------------
                  Total |        100      100.00
            
            . recode NewNumVerifiers (0 = .) (13 16 24 29 30 = 1 "Audit Firm") (* = 0 "Not Audit Firm"), gen
            > erate(AuditFirm)
            (100 differences between NewNumVerifiers and AuditFirm)
            
            . label variable AuditFirm "Audit Firm"
            
            . tab AuditFirm
            
                Audit Firm |      Freq.     Percent        Cum.
            ---------------+-----------------------------------
            Not Audit Firm |         16       76.19       76.19
                Audit Firm |          5       23.81      100.00
            ---------------+-----------------------------------
                     Total |         21      100.00

            Comment


            • #7
              Thank you so much to both of you! This is indeed very helpful!

              Comment

              Working...
              X