Announcement

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

  • Coefplot with by(label) option - Not working

    Hi All

    I'm trying to run the below code to visualize odds ratios from three separate logistic regression models (figure attached). Overall, the code works but I'm unable to include the 'by(label)' option correctly. I've tried placing it in different parts of the code but I only get errors. I'd like to have a separate label for each of the three sets of estimates:

    Code:
    coefplot (est1, mcolor(gray) ciopts(lcolor(gray))) ///
                  (est2, mcolor(black) ciopts(lcolor(black))) ///
                  (est3, mcolor(navy) ciopts(lcolor(navy))), xlabel (0(0.5)2) eform xtitle(OR (95% CI)) xline(1, lwidth(thin) lcolor(red)) drop(_cons gender2.Female 1.imd_5 2.imd_5 3.imd_5 4.imd_5 5.imd_5)

    Example code of where I initially thought the 'by(label') option should be placed (but I've tried placing the option elsewhere like after the est1):

    Code:
    coefplot (est1, mcolor(gray) ciopts(lcolor(gray))) bylabel(Heart) ||  ///
             (est2, mcolor(black) ciopts(lcolor(black))) bylabel(Digestive) ||  ///
             (est3, mcolor(navy) ciopts(lcolor(navy))) bylabel(Respiratory) || , xlabel (0(0.5)2) eform xtitle(OR (95% CI)) xline(1, lwidth(thin) lcolor(red)) drop(_cons gender2.Female 1.imd_5 2.imd_5 3.imd_5 4.imd_5 5.imd_5)

    Further, I'm unable to drop the estimate for gender (but I was able to drop all other unwanted estimates!). I think this how to do with how the gender categories were labelled:

    Code:
    . tab gender2
    
         GENDER |      Freq.     Percent        Cum.
    ------------+-----------------------------------
         Female |      8,867       42.95       42.95
           Male |     11,779       57.05      100.00
    ------------+-----------------------------------
          Total |     20,646      100.00

    Code:
    ------------------------------------------------------------------------------------------------------------------------------------
    gender2                                                                                                                       GENDER
    ------------------------------------------------------------------------------------------------------------------------------------
    
                      Type: Numeric (long)
                     Label: gender2
    
                     Range: [1,2]                         Units: 1
             Unique values: 2                         Missing .: 0/20,646
    
                Tabulation: Freq.   Numeric  Label  
                            8,867         1  Female
                           11,779         2  Male

    Any help would be really appreciated!

    Thanks
    /Amal

    Click image for larger version

Name:	Graph example.png
Views:	2
Size:	59.4 KB
ID:	1759858
    Attached Files

  • #2
    coefplot is from SSC, as you are asked to explain (FAQ Advice #12). There are no separate panels in your graph, so you likely want the -label()- option instead. Otherwise, post a data example and explain what you need if this does not solve your problem.

    Comment


    • #3
      Thanks for your reply but I don't think I understood...

      In another example, I used the 'by label' option ('full sample', 'males' and 'females') which worked. But here I used the keep option to choose the estimates from the three regression models. However, the keep option is not working with my original example above (I get a message saying coefficients not found which is perplexing):


      Code:
      coefplot (est1), keep(MH___1_RB: MH___2_RB: MH_____3_RB:) bylabel(full sample) || ///
               (est2), keep(MH___1_RB: MH___2_RB: MH_____3_RB:) bylabel(Males) || ///
               (est3), keep(MH___1_RB: MH___2_RB: MH_____3_RB:) bylabel(Females) drop(_cons 1.ethnic2cat 2.ethnic2cat 3.ethnic5cat 4.ethnic5cat 1.incomeq3 2.incomeq3 3.incomeq3 4.incomeq3 5.incomeq3 1.sex 2.sex) xlabel (0(2)13) eform xtitle(RRR (95% CI)) xline(1, lwidth(thin) lcolor(red))

      I'm essentially trying to replicate the above which my original code in the first message.

      Also, my other question was in relation to me being unable to drop the coefficient for female (but I was able to drop all others).

      Thanks
      /Amal

      Comment


      • #4
        As I said in #2, present a data example. You can use one of Stata's dataset, if not your own, or some other dataset.

        Comment

        Working...
        X