Announcement

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

  • Twoway scatter with custom line plot from linear regressions

    I have performed a linear regression model to investigate the association between a GaitScore and Pain adjusted for age and sex

    . regress GaitScore Pain age i.sex

    This create the regression model

    GaitScore| Coef. Std. Err. t P>|t| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    Pain | -1.030371 .5217701 -3.02 0.004 -2.656475 -0.55933
    age | -0.301733 0.201676 -1.53 0.122 -.0005076 0.090161
    sex | -2.065706 2.0057716 -0.67 0.480 -.2116815 3.685403
    _cons | 49.68492 6.329089 7.85 0.000 37.06195 62.30789
    ------------------------------------------------------------------------------

    If I then plot a twoway scatter with the lfit line
    . twoway (scatter GaitScore Pain) (lfit GaitScore Pain)

    This draws the scatter with the prediction plots (or how a simple regression linear would look GaitScore, Pain)
    However the line I really wanted is the regression line for Pain adjusted for age and sex.

    GaitScore = 49.7 + -1.03*Pain

    Is that possible, preferable form the stored results from the regression model or manually by writing the formula for the line?

    Hope my question is clear..


    I am using Stata version 13.1, windows 7,

    Thanks in advance

    Kind regards
    Dennis Nielsen
    Biomedical engineer

  • #2
    Code:
    sysuse auto.dta , clear
    twoway (scatter mpg weight)(function y = 39 -0.006*x, range(weight))

    Comment


    • #3
      The -margins- and -marginsplot- post-estimation commands are very powerful and can do what you want. Unfortunately, I don't know the range and measurement scale) of your data so I can't give you an exact command, but something like the following could work:
      Code:
      regress GaitScore Pain age i.sex
      margins sex, at(GaitScore=(0(1)10))
      marginsplot, recast(line) noci
      Best,
      Alan

      Comment


      • #4
        Thanks so much for all your help.. a special thanks to Svend for some great books on Stata as well.. and thanks to Alan for introducing me to the marginsplot command I have already become quite fond of it... Thanks again..

        Kind Regards
        Dennis

        Comment

        Working...
        X