Announcement

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

  • marginsplot with a constant (downward shift)

    Dear all,

    I am using the marginsplot command to create a graph which includes a confidence interval at each point.

    However I want the starting point of the graph to be (0,0) and thus I need to take away one specific value from every point in the graph (a downward shift).

    For example, if the graph starts at (0,25), I would need to take away 25 at every point for the graph to start at (0,0)

    The code I am currently using is listed below.

    Code:
    svy: reg y x1 x2 x3 x4
    margins, at(x1=(0(1)11))
    marginsplot, recastci(rarea)
    If anyone knows how to create a downward shift, I'd be extremely appreciative if you could let me know.

    I am using Stata 15.1 for Windows 10.

    Many thanks in advance,
    James Clarke.

  • #2
    You could use the -post- option on margins and then reconstruct the graph from e(b) and e(V)

    Or, extract the data from the original graph, make adjustments, and then replot:
    Code:
    sysuse auto,clear
    
    reg price mpg weight
    qui margins, at(weight=(2000(1000)5000))  
    marginsplot
    serset use
    gen mymargin = _mar - _mar[1]
    gen lb = _ci_lb - _marg[1]
    gen ub = _ci_ub - _marg[1]
    rename __0  at
    line mymargin at || rcap ub lb at

    Comment


    • #3
      Also, you can use the -expression()- option. Though the CI will different:
      Code:
      sysuse auto,clear
      
      reg price mpg weight
      qui margins, at(weight=(2000(1000)5000))  
      mat a = r(table)
      local a2 = a[1,1]
      margins, at(weight=(2000(1000)5000))  expression(predict(xb) - `a2' )
      marginsplot

      Comment


      • #4
        Dear Scott,

        Thank you so much for the help.

        I can confirm that your code from your first response worked perfectly.

        James.

        Comment

        Working...
        X