Announcement

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

  • Marginsplot after difference in difference using xi:diff

    Hello Experts,

    I am doing a difference-in-difference analysis using Stata 15.1 (using the following code), the outreg2 works but when I try to do a margins command to get a marginsplot, I get an error code:
    Code:
    xi:diff married [pweight=wt] if agegr3==1, t(cat) p(survey) cluster(hv021)
    margins , pred(pr) at (cat=(0 1)) over(survey) vsquish post 
    variable __000002 not found
    r(111);
    xi:diff married [pweight=wt] if agegr3==1, t(cat) p(survey) cov (i.agegr3 i.hv104) cluster(hv021) kernel rcs
    est store z1
    outreg2 using table_diff, ctitle(`r(Currently married)') addstat(Mean control t(0), r(mean_c0), Mean treated t(0), r(mean_t0), Diff t(0), r(diff0), Mean control t(1), r(mean_c1), Mean treated t(1), r(mean_t1), Diff t(1), r(diff1)) label excel nocons
    est restore z1
    margins , pred(pr) at (cat=(0 1)) over(survey) vsquish post 
    variable __00000C not found
    r(111);
    xi:diff married [pweight=wt] if agegr3==1, t(cat) p(survey) cov (i.hv025 i.hv104 i.agegr3 i.hhsize i.foreign i.eduhead) cluster(hv021) kernel rcs
    est store z2
    outreg2 using table_diff, ctitle(`r(Currently married)') addstat(Mean control t(0), r(mean_c0), Mean treated t(0), r(mean_t0), Diff t(0), r(diff0), Mean control t(1), r(mean_c1), Mean treated t(1), r(mean_t1), Diff t(1), r(diff1)) label excel nocons
    est restore z2
    margins , pred(pr) at (cat=(0 1)) over(survey) vsquish post 
    variable __00000C not found
    r(111);

    Can someone please explain why I am getting these errors and how I can get the margins & marginsplot commands to work?

    Thank you
    Deepali
    Deepali Godha

  • #2
    -xi- is incompatible with -margins- and -marginsplot-. In current Stata, and even back in version 15.1, there is hardly any use for -xi- any more. You should tuck it away in some dusty corner of your brain, almost forget it exists. Use factor-variable notation anywhere you would have previously used -xi-. See -help fvvarlist-There are only a handful of places where that won't work. And those are mostly obscure, more or less obsolete commands whose functions have been superceded by newer commands that do support factor-variable notation, or user-written commands.

    That said, -diff- is not an official Stata command, and I do not know if it supports factor-variable notation or not. If it doesn't, then you can't use -margins- and -marginsplot- with it. You would need to construct your own DID regression using -xtreg- or similar commands in that case.

    Comment


    • #3
      Thank you Clyde, for the logic behind the errors. Also, you are right that diff does not support factor-variable notion.
      Deepali Godha

      Comment


      • #4
        Hello Clyde,

        I just realized that I do have the "__000002" and "__00000C" information in my output (see below). Is there a way I can fill this information manually to get the margins command to work?

        Code:
         
        Linear regression Number of obs = 8,270
        F(3, 577) = 2.69
        Prob > F = 0.0453
        R-squared = 0.001
        Root MSE = 0.24433
        (Std. Err. adjusted for 578 clusters in hv021)
        Robust
        __000001 Coef. Std. Err. t P>t [95% Confidence Interval]
        survey -0.02205 0.007792 -2.83 0.005 -0.0373535 -0.00675
        cat -0.00954 0.011074 -0.86 0.389 -0.0312942 0.012206
        __00000C 0.018284 0.01523 1.2 0.23 -0.0116279 0.048196
        _cons 0.073174 0.005831 12.55 0 0.0617208 0.084628
        Thank you
        Deepali
        Deepali Godha

        Comment


        • #5
          Not that I know of. If the -diff- output includes the regression command that generated that output table, you might be able to edit that command to use factor-variable notation, run the edited command, and then invoke -margins-. If not, then I think you need to just figure out on your own what the regression command would be, write it using factor variable notation, and then go with that.

          Comment


          • #6
            Thank you Clyde.
            Deepali Godha

            Comment

            Working...
            X