Announcement

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

  • change baseline category for labeled variables

    Dear all,

    I wonder whether there is a way to change the baseline category for labeled variables without having to remove the labels.

    I tried the following:

    tnbreg outcome ib2.var1

    var1 is a variable with 4 categories (1-4) and assigned labels. I can run the code, but in the output the reference category still doesn't change.

    Many thanks!

    Isabel

  • #2
    I can't replicate in Stata 14. This seems to work fine:

    Code:
    webuse rod93, clear
    tnbreg deaths i.cohort, ll(9) nolog
    tnbreg deaths ib2.cohort, ll(9) nolog
    tnbreg deaths ib3.cohort, ll(9) nolog
    Make sure your copy of Stata is up to date, i.e. run -update all-. If problems persist post your code and output (using code tags like I just did).
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      I'm using Stata 13 and just run an update, but still I can't change the baseline category.

      I'm running the following code:
      Code:
      tnbreg anzbes   i.rasse_cat
      This is the output:
      Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	13.9 KB
ID:	1297206



      I get exactly same output when I run the code as follows:
      Code:
      tnbreg anzbes   ib3.rasse_cat
      or
      Code:
      tnbreg anzbes   ib4.rasse_cat


      The variable rasse_cat is coded 1-5 and labeled with the above shown labels. These are two print screens from the data editor:
      Click image for larger version

Name:	Capture2.JPG
Views:	1
Size:	12.3 KB
ID:	1297207
      Click image for larger version

Name:	Capture3.JPG
Views:	1
Size:	15.2 KB
ID:	1297208


      If I run the code for a non-labeled variable I can change the baseline category without any problems!

      Comment


      • #4
        Isabel:
        what does Stata give you back after typing -label list-?
        Kind regards,
        Carlo
        (StataNow 18.5)

        Comment


        • #5
          Hi Carlo,
          I get the following output:

          Click image for larger version

Name:	Capture4.JPG
Views:	1
Size:	11.8 KB
ID:	1297216


          Seems to be fine?

          Comment


          • #6
            Isabel:
            your output makes sense.
            Hence, I would scrutiny your dataset in search of different explanations.
            In fact, changng the reference category in the categorical predictor should give you different coefficients, as in the following toy-example, which elaborates on a bit on an Stata 13.1 example:
            Code:
            use http://www.stata-press.com/data/r13/medproviders
            label define age 1 first 2 second 3 third 4 fourth 5 fifth 6 sixth 7 seventh 8 eighth 9 ninth
            label val age age
            tnbreg los died hmo i.age
            tnbreg los died hmo ib(3).age
            Kind regards,
            Carlo
            (StataNow 18.5)

            Comment


            • #7
              Try running the code that either Carlo or I posted, and see if it works correctly. If it doesn't it may be that your installation of Stata is corrupted. If it does work then post all of your code. It may be there is some step you are not showing us that is creating the problem. If there is any way for you to provide us with a replicable example, that could help too.
              -------------------------------------------
              Richard Williams, Notre Dame Dept of Sociology
              StataNow Version: 19.5 MP (2 processor)

              EMAIL: [email protected]
              WWW: https://www3.nd.edu/~rwilliam

              Comment


              • #8
                The code that Carlo posted is running fine in my Stata 13.
                Here is the code I'm using to label the variable. 'rasse' is a string variable, I created 'rasse_cat' to make it numerical. Maybe there's an issue here?

                Code:
                gen rasse_cat = 1 if rasse=="BV"
                replace rasse_cat = 1 if rasse=="BS"
                replace rasse_cat = 1 if rasse=="OB"
                replace rasse_cat = 2 if rasse=="HO"
                replace rasse_cat = 2 if rasse=="RH"
                replace rasse_cat = 2 if rasse=="RF"
                replace rasse_cat = 3 if rasse=="SF"
                replace rasse_cat = 4 if rasse=="SI"
                replace rasse_cat = 4 if rasse=="60"
                replace rasse_cat = 4 if rasse=="70"
                replace rasse_cat = 5 if rasse_cat!=0 & rasse_cat!=1 & rasse_cat!=2 & rasse_cat!=3 & rasse_cat!=4 & rasse!=""
                tab rasse_cat, missing
                
                label define lab_rasse  1 "BS/OB/BV" 2 "HO/RH/RF" 3 "SF" 4 "SI" 5 "other"
                label values rasse_cat lab_rasse

                Comment


                • #9
                  I also just tried to run the code with another labeled predictor variable (Sym12_cat), and it was working fine! So there must be an explicit problem with the labeling of 'rasse_cat'.

                  Here is the code for the other labeled categorical variable that is running fine
                  Code:
                  gen Sym12_cat = 0 if Sym12==0 & Fall==0
                  replace Sym12_cat= 1 if Sym12==0 & Fall==1
                  replace Sym12_cat= 2 if Sym12==1 & Fall==1
                  
                  label define lab_sym2  0 "Sym0 Fall0" 1 "Sym0 Fall1" 2 "Sym1 Fall1" 
                  label values Sym12_cat lab_sym2

                  Comment


                  • #10
                    Isabel:
                    now that I see your last reply, I would investigate what happens after you have turned -rasse- into a numeric variable, -label(led)- it and re-run -tnbreg-.
                    Kind regards,
                    Carlo
                    (StataNow 18.5)

                    Comment


                    • #11
                      Carlo, this code is working:

                      Code:
                      replace rasse = "1" if rasse=="BS" | rasse=="OB" | rasse=="BV" 
                      replace rasse = "2" if rasse=="HO" | rasse=="RH" | rasse=="RF" 
                      replace rasse = "3" if rasse=="SF"
                      replace rasse = "4" if rasse=="SI"
                      replace rasse = "5" if rasse!="1" & rasse!="2" & rasse!="3"  & rasse!="4" 
                      destring rasse, replace
                      
                      label define lab_rasse  1 "BS/OB/BV" 2 "HO/RH/RF" 3 "SF" 4 "SI" 5 "other"
                      label values rasse lab_rasse
                      tnbreg besamungsnr ib4.rasse
                      I will just code it this way then!. But still it is not very clear to me why the above code is not working.

                      Comment


                      • #12
                        isabel:
                        thanks for posting that.
                        As far as the "above code" is concerned, did you check whether the attached value labels were the right ones (something similar occurred to me some years ago)?
                        Kind regards,
                        Carlo
                        (StataNow 18.5)

                        Comment


                        • #13
                          Thank you for all your inputs! I actually just tried my "original" code again and removed the string signs ("") in the label define command. I got an error message and put them back - since then the code is working fine! I don't know where exactly the problem was, but at least it is working now

                          Comment


                          • #14
                            Isabel.
                            thanks for closing out the thread positively.
                            For what it worths, I have tried to follow a pattern similar to yours in labelling a string variables.
                            I do not know whether the following toy-example can give you some further inputs for sniffing out the culprit (just out of curiosity, indeed, as you worked around your problem successfully):
                            Code:
                            use "http://www.stata-press.com/data/r13/auto.dta", clear
                            g Code_auto="Alpha" in 1/30
                            replace Code_auto="Beta" in 31/50
                            replace Code_auto="Gamma" in 51/74
                            g Cat_Code_auto=1 if Code_auto=="Alpha"
                            replace Cat_Code_auto=2 if Code_auto=="Beta"
                            replace Cat_Code_auto=3 if Code_auto=="Gamma"
                            label define Cat_Code_auto 1 Alpha 2 Beta 3 Gamma
                            label val Cat_Code_auto Cat_Code_auto
                            label list Cat_Code_auto
                            reg price i.Cat_Code_auto
                            reg price ib(3).Cat_Code_auto
                            Last edited by Carlo Lazzaro; 08 Jun 2015, 06:56.
                            Kind regards,
                            Carlo
                            (StataNow 18.5)

                            Comment

                            Working...
                            X