Announcement

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

  • Code needed: scatterplot with main regression line and other multiple ones

    Dear all,

    I have panel data with observations consists of multiple groups.

    I need to draw a scatter plot of DV versus IV with a line that represents the linear regression of entire observations, and also, regression lines of the groups (entities) with observation points shown.

    Here is an example of what I precisely need.

    Screen Shot 2021-05-26 at 2.51.48 PM.png


    Also, If you have a good and sufficient webpage, plot, or document that shows examples of various figures describing panel data and their codes, may you send it to me?
    I know that manuals provide good guidance, but since I am new to Stata, I find it difficult to find what exactly need and follow instructions.

    Thank you in advance,
    Huss

  • #2

    Here is one way:
    Code:
    sysuse auto,clear
    scatter price mpg if foreign == 0, mc(blue) ms(t)  /// 
        text(2700 27 "Domestic" , size(*.75) color(blue)  ) /// 
        || lfit price mpg  if fore == 0 ,  lc(blue)  /// 
        || scatter price mpg if fore == 1 , mc(green) ms(Oh) /// 
        text(5000 33 "Foreign"  , size(*.75) color(green) ) /// 
        ||lfit price mpg if fore == 1,  lc(green) /// 
        ||  lfit price mpg,  lc(black) lw(thick) /// 
        text(2200 35 "Regression"  , size(*.75) ) /// 
        ||, legend(off)

    Comment


    • #3
      Also, If you have a good and sufficient webpage, plot, or document that shows examples of various figures describing panel data and their codes, may you send it to me?
      Here's a couple to start

      https://www.princeton.edu/~otorres/Panel101.pdf
      https://www.iuj.ac.jp/faculty/kucc62.../panel_iuj.pdf

      Comment


      • #4
        thank you Justin Niakamal and Justin Niakamal

        Comment

        Working...
        X