Announcement

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

  • Confidence intervals margins plot: confusing

    Hi list,

    I have issues with the margins command and (too many) overlaping confidence intervals. As you might see from the picture, it is hard to tell what is actually happening at the right most side of the plot beneath. I have runned what is sometimes refered to as a "difference-in-differnce-in-differences" (http://www.nber.org/WNE/lect_10_diffindiffs.pdf) model and then I use margins to show linear predictions. My problem is that the confidence interval makes it look messy, and I can't tell them apart.



    Year is a time indicator [0;1], D is a treatment indicator [0;1] and dE [0;1 ]is the third variable that I'm interested in. (I want to see if the treatment is different for persons who have dE==0 and 1.)

    Code:
    reg outcome year##D##dE, vce(cluster identifyer) 
    margins, at (year=(0 1) D=(0 1) dE=(9 1)) 
    marginsplot, xline(0.3)
    My question is: is there a way to get Stata to estimate margins for year=0.98 for one group, or something like that - so I can visually distinguish the confidence intervals?

    When I try to do

    Code:
    reg outcome year##D##dE, vce(cluster identifyer) 
    margins, at (year=(0 0.98 1) D=(0 1) dE=(9 1)) 
    marginsplot, xline(0.3)
    I get a warning saying: "at level for factor year not present in estimation".

    I tried to do something like this:
    Code:
    reg outcome year##D##dE, vce(cluster identifyer) 
    predict Y
    replace year = 0.98 if dE==1 & year==1
    collpase Y, by(year D dE)
    gr two (connect Y year if D==0 & dE==0)///
              (connect Y year if D==0 & dE==1)///
              (connect Y year if D==1 & dE==0)///
              (connect Y year if D==1 & dE==1), xline(0.3)
    But the lines are not exactly the same as in the margins plot, and there is of course no confidence intervals at all.

    In other words, I would simply like to push e.g. the two dashed lines a little down the axis to better see what is actually happening in the plot.
    Click image for larger version

Name:	pred.png
Views:	1
Size:	43.9 KB
ID:	1527500

  • #2
    Check mplotoffset from SSC

    Comment


    • #3
      Hi Andrea,

      Thanks for you answer. My problem is that I'm working on protected serves without internet access so I cannot install new packages.

      Comment


      • #4
        You may also try to make a little distance in the x-axis between the values, just for the sake of providing a nice display.
        Best regards,

        Marcos

        Comment


        • #5
          Hi Marcos,

          Yes, that's exactly what I want to do, but I can't figure out how to do that

          Comment


          • #6
            In your code
            Code:
            reg outcome year##D##dE, vce(cluster identifyer)
            margins, at (year=(0 1) D=(0 1) dE=(9 1))
            marginsplot, xline(0.3)
            I believe that since you don't specify any prefix for any of the variables year, D, and dE, Stata interprets all three to be factor variables. This is why when you try
            Code:
            margins, at (year=(0 0.98 1) D=(0 1) dE=(9 1))
            it gives you the error. Since year is a factor variable it can only take values of 0 or 1.

            The simplest solution would, I think, be
            Code:
            reg outcome c.year##D##dE, vce(cluster identifyer)
            margins, at (year=(0 0.98 1) D=(0 1) dE=(9 1))
            marginsplot, xline(0.3)
            Here year is treated as a continuous variable. It shouldn't change the results of the regression, and when using margins it won't give you an error (I think). I don't know if that will get you what you're looking for, but one can only hope.
            Alfonso Sanchez-Penalver

            Comment

            Working...
            X