Announcement

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

  • Coefplot: Displaying each level of a factor variable in one plot

    Greetings:

    I am trying to visualize the data for logistic regressions. My independent variable of interest is a categorical variable with 18 levels. I am trying to use coefplot (or anything is stata) to make a chart of the different AORs and the confidence intervals but I can't seem to find a way. The closest I've seen is that I can use coefplot to graph interaction variables and it'll include each level of the interaction and I can drop the covariates to isolate the results of my IVs on interest. I cannot seem to figure out how to do it for one variable with multiple levels.

    First problem that occurs. I use the following code:

    coefplot poorhealth, drop(agecat_v3 education hh_child partnered hh_income nonenglish uninsured no_usualcare state year) xline(1)

    And I get this :

    Click image for larger version

Name:	Screen Shot 2021-02-25 at 12.37.33 PM.png
Views:	2
Size:	1.04 MB
ID:	1595070

    I can't seem to get past the first step. Any help would be greatly appreciated.

    Thank you
    Attached Files

  • #2
    coefplot is from the Stata Journal (FAQ Advice #12).

    Code:
    webuse nlswork
    set seed 02262021
    gen catvar= runiformint(1,18)
    logit union age i.race i.catvar grade collgrad
    coefplot, keep(*.catvar) baselevels sort scheme(s1mono)
    Res.:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	50.5 KB
ID:	1595182


    Comment


    • #3
      Originally posted by Ellesse Akre View Post
      Greetings:

      I am trying to visualize the data for logistic regressions. My independent variable of interest is a categorical variable with 18 levels. I am trying to use coefplot (or anything is stata) to make a chart of the different AORs and the confidence intervals but I can't seem to find a way. The closest I've seen is that I can use coefplot to graph interaction variables and it'll include each level of the interaction and I can drop the covariates to isolate the results of my IVs on interest. I cannot seem to figure out how to do it for one variable with multiple levels.

      ...
      A point of information because you mentioned adjusted odds ratios: even if you used the logistic command (which shows odds ratios), coefplot plots the coefficients in their raw scale (i.e. in log-odds units). You can verify this by comparing your chart to the odds ratio outputs. Or, you drew a line through x = 1, but a whole bunch of your coefficients are around x = 0, i.e. an odds ratio of 1.

      This is easy to solve, you just add the eform option as detailed here. One thing to remember is that the confidence intervals will be asymmetric - they're symmetric on the log-odds scale, but they asymmetric once you exponentiate everything. Some people may get nervous about this, but that is the nature of logistic regression.
      Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

      When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

      Comment


      • #4
        Thank you both! this is extremely helpful and I was able to get the correct chart.

        Comment

        Working...
        X