Announcement

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

  • Graph adjusted line?

    Do you know if it is possible to graph a line, adjusted for confounders? In this example it looks like there is a rise in haemoglobin with dietary greenhouse gas emissions, but this is because men usually have higher haemoglobin and higher greenhouse gas emissions than women. In this example – can I draw a line adjusted for sex? Does the first line in my code actually do anything?

    code:
    regress HGB Total_CO2 i.SEX
    twoway (lfit HGB Total_CO2) || (lfit HGB Total_CO2 if SEX==0) || (lfit HGB Total_CO2 if SEX==1), ytitle(HGB) xtitle("Dietary GHGE (kg/day)")

    Click image for larger version

Name:	Regression.png
Views:	3
Size:	44.8 KB
ID:	1723967

  • #2
    Code:
    help margins
    Code:
    regress HGB Total_CO2 i.SEX
    margins SEX, at(Total_CO2=(1/25))
    marginsplot

    Comment


    • #3
      Thank you! Now i get 2 lines, one for men, one for women. Can I get only one line?

      Comment


      • #4
        Omit the gender variable if you want the overall margin.

        Comment


        • #5
          Thank you for your expertise so far. Hopefully this is my last question this time.

          Why does my line look exactly the same with this codes, when my regression coefficient is not the same? It seems like it is not graphing the coefficient with covariates in the model.


          regress HGB AGE Total_CO2
          twoway lfit HGB Total_CO2

          regress HGB Total_CO2
          twoway lfit HGB Total_CO2

          Comment


          • #6
            As illustrated in #2, margins will give you the adjusted predictions and marginsplot will plot them. twoway is a graphing command and does not take into account any commands ran before it. The graphs are the same because the two calls to twoway are the same.


            twoway lfit HGB Total_CO2

            Comment


            • #7

              So it is not possible to plot a simple regression line based on your coefficient with more variables in the model? Do I have to do it manually?
              Click image for larger version

Name:	Bild1.JPG
Views:	1
Size:	125.4 KB
ID:	1724215

              Comment


              • #8
                Check out added variable plots.

                Code:
                help avplots 
                
                search favplots
                Not quite what you're asking for, but often as or more useful.

                Comment


                • #9
                  I have checked the help section but I cannot find the information I need. See explanation below:
                  Click image for larger version

Name:	Bild1.JPG
Views:	1
Size:	151.2 KB
ID:	1724221

                  Comment


                  • #10
                    I would just be guessing if I tried again with a code suggestion. But my guess is that you want a graph for each predictor that will be less informative than an added variable plot, so I will stop there.

                    Comment


                    • #11
                      Thank you for your time! I am new to Stata and I am sorry if I have misunderstood something. I will keep learning :-)

                      Comment

                      Working...
                      X