Announcement

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

  • creating a line graph following margins - previous command was not margins

    Aim: To create a graph similar to this. Where the graph of course only has the blue line. The x axis is the age
    I then want to repeat this for procedure==0 and overlay both graphs onto each other to get 2 lines instead.

    score, age are continuous variables
    Code:
    regress score age i.asa if procedure==1
    margins age, at(age=50(10)100)
    //This returns an error: previous command was not margins

    How can I modify this code for it to work pls?

    Click image for larger version

Name:	statahelp.PNG
Views:	1
Size:	17.0 KB
ID:	1740174


  • #2
    I'm not entirely sure I understand what you want, but I think it's
    Code:
    regress score i.procedure##(c.age i.asa)
    margins procedure, at(age=50(10)100)
    marginsplot, xdimension(age)

    Comment


    • #3
      Thanks for this

      however I see you’ve changed the regress command

      from

      Code:
      regress score age i.asa if procedure==1
      
      ////to CS version
      
      regress score i.procedure##(c.age i.asa)
      Q1
      is there a reason why you decided to insert an interaction terms between age and asa ?

      Q2
      is there a reason why you omitted -if procedure==1

      As my plan was to repeat the regression and subsequent steps for procedure ==1 and procedure ==0 and produce two separate line graphs. Then combine both line graphs to get two lines on the same graph (just like the picture in initial post)

      or perhaps you’re showing me a shortcut rather than my way and doing all these steps

      Comment


      • #4
        Clyde's is showing you a shortcut. His syntax obviates the need to run separate regressions for procedure groups. You can add an interaction of procedure with sex and asa. This is the way to use a single model to get all the parameter effects you would get when running separate models. If you do not want the asa#age interaction, then just change the syntax to remove asa from the parentheses.

        Clyde's approach uses all the data to estimate the coefficients and the margins. I am not sure why it would be problematic to have a single graph with all lines, but that is personal preference.

        Comment


        • #5
          Hello there,
          I've retried

          Code:
          regress score i.procedure##(c.age i.asa) [pw=weight]
          margins procedure, at(age=50(10)100)
          marginsplot, xdimension(age)
          Stata returns the error:
          (10) invalid statistic...

          What am I doing wrong?

          Comment


          • #6
            Clyde probably did not test his code. The syntax for numlists is

            Code:
            margins ... , at(age = (50(10)100))

            Comment


            • #7
              Note just solved this
              **error the code should be:

              Code:
              regress score i.procedure##(c.age i.asa) [pw=weight]
              margins procedure, at(age=(50(10)100))

              Comment

              Working...
              X