Announcement

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

  • Problem with combomarginsplot

    I am hoping to compare two time trends in my data: (a) the raw trend in my outcome variable y over the years, and (2) the trends in y if I control for month and predict at a certain month. So I'm running:

    Code:
    svy: reg wasting2 i.year
        margins year, saving(f1, replace)
    svy: reg wasting2 i.year i.monthint
        margins year, at(monthint=6) saving(f2, replace)
    
    combomarginsplot f1 f2
    Each of these margins commands produces a prediction over the same years, and marginsplot produces close to identical graphics for each. Yet combomarginsplot fails because of the at(monthint=6). The error I get is this: file 2 _u_at_vars don't match file 1.


    I can reproduce this error in the auto data:

    Code:
    sysuse auto.dta, clear 
    gen binmpg = round(mpg)
    
    reg price i.foreign
        margins foreign, saving(f1, replace)
        marginsplot 
        
    reg price i.foreign i.binmpg
        margins foreign, at(binmpg=20) saving(f2, replace)
        marginsplot 
    
    combomarginsplot f1 f2
    Again, I see no reason why these two graphics should NOT be shown overlaid (I've added individual marginsplot commands to illustrate that the two graphics are set up identically), but combomarginsplot will not allow it. Is there any way around this problem? Thanks!

  • #2
    Hi Leah,
    I dont think you can change the behavior of -combomarginsplot-.
    Instead what you can do is grab the files it creates, and replot everything yourself

    Something like this:

    Code:
    sysuse auto.dta, clear 
    gen binmpg = round(mpg)
    reg price i.foreign
        margins foreign, saving(f1, replace)
    reg price i.foreign i.binmpg
        margins foreign, at(binmpg=20) saving(f2, replace)
    use f1, clear
    append using f2
    replace _m1 = _m1+0.1 in 3/4
    replace _m1 = _m1-0.1 in 1/2
    two rspike _ci_lb _ci_ub _m1 in 1/2|| scatter _margin _m1 in 1/2 || rspike _ci_lb _ci_ub _m1 in 3/4 || scatter _margin _m1 in 3/4, legend(off) xlabel(0 "Domestic" 1 "foreign")

    Comment

    Working...
    X