Announcement

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

  • Marginsplot with catagorical variables on x axis - custom spacing

    I have a dataset where the outcome is binary (y), and a predictor variable is in the form of ordinal categories (x). These ordinal categories, for the data that I'm analysing, are numbered 2, 3, 4, 6, 7, and 8. There was no type 5 condition for these data.

    I ran the logistical regression (logistic germinated i.s_treatment), and then margins (margins i.s_treatment) for the categories.
    Delta-method
    Margin Std. Err. z P>z [95% Conf. Interval]
    s_treatment
    2 .2158891 .0190877 11.31 0.000 .1784779 .2533003
    3 .226945 .0194258 11.68 0.000 .1888712 .2650188
    4 .2810673 .0198444 14.16 0.000 .2421729 .3199617
    6 .3776728 .0224277 16.84 0.000 .3337153 .4216304
    7 .2911443 .0210381 13.84 0.000 .2499104 .3323781
    8 .3500235 .0206868 16.92 0.000 .3094782 .3905688
    I then ran marginsplot.

    Marginsplot includes a space where category 5 should be, treating it as if it were a continuous variable. I want to remove this gap, is there a simple way to do so?
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	109.0 KB
ID:	1615769
    Last edited by John Porter; 22 Jun 2021, 08:17.

  • #2
    Code:
    egen s2_treatment= group(s_treatment), label
    Then use s2_treatment in place of s_treatment.

    Comment


    • #3
      An elaboration on Andrew's reply:
      Code:
      sysuse auto,clear
      //Create gap
      replace rep = rep+1 if rep > 3
      
      egen temp_rep = group(rep), label
      local lab: variable label rep
      label variable temp_rep "`lab'"
      
      qui reg price i.temp_rep
      qui margins i.temp_rep
      marginsplot, xlabel(1(1)3 4 "5" 5 "6")

      Comment


      • #4
        Thanks for that example, Scott. But note that the xlabel option seems to be unnecessary. Running the code below, I find that the g1 and g2 plots are identical.

        Code:
        qui reg price i.temp_rep
        qui margins i.temp_rep
        marginsplot
        graph rename g1
        marginsplot, xlabel(1(1)3 4 "5" 5 "6")
        graph rename g2
        Cheers,
        Bruce
        --
        Bruce Weaver
        Email: [email protected]
        Version: Stata/MP 18.5 (Windows)

        Comment


        • #5
          Originally posted by Bruce Weaver View Post
          Thanks for that example, Scott. But note that the xlabel option seems to be unnecessary. Running the code below, I find that the g1 and g2 plots are identical.

          As you are labeling the grouped variable (using the -label- option of egen), it will take the to be grouped variable's labels if it is labeled, otherwise it will take its values as labels. So, indeed, modifications to the x-axis labels are unnecessary.

          Comment

          Working...
          X