• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Institute for Digital Research and Education

Image

  • HOME
  • SOFTWARE
    • R
    • Stata
    • SAS
    • SPSS
    • Mplus
    • Other Packages
      • G*Power
      • SUDAAN
      • Sample Power
  • RESOURCES
    • Annotated Output
    • Data Analysis Examples
    • Frequently Asked Questions
    • Seminars
    • Textbook Examples
    • Which Statistical Test?
  • SERVICES
    • Remote Consulting
    • Services and Policies
      • Walk-In Consulting
      • Email Consulting
      • Fee for Service
      • FAQ
    • Software Purchasing and Updating
    • Consultants for Hire
    • Other Consulting Centers
      • Department of Statistics Consulting Center
      • Department of Biomathematics Consulting Clinic
  • ABOUT US

Spaghetti Plots in Stata

Here are a couple of examples of making spaghetti plots.
Here is a basic spaghetti plot that looks at "alcuse" over time (age_14) showing
one regression line per person (see "search spagplot")
spagplot alcuse age_14 , id( id ) 
Image spag.h1
Here we make the same graph manually.
use https://stats.idre.ucla.edu/stat/stata/examples/alda/data/alcohol1_pp, clear

quietly xi: regress alcuse i.id*age_14
predict yhat
graph twoway line yhat age_14, connect(L L)

And here is the graph
Image spag.h2
But say that you wanted to see separate lines for males and females.  We can
do that, as shown below.
use https://stats.idre.ucla.edu/stat/stata/examples/alda/data/alcohol1_pp, clear

separate alcuse, by(male)
quietly xi: regress alcuse0 i.id*age_14
predict yhat0
quietly xi: regress alcuse1 i.id*age_14
predict yhat1

graph twoway line yhat0 yhat1 age_14, connect(L L)
and here is the graph
Image spag.h3

 

Primary Sidebar


Click here to report an error on this page or leave a comment

    How to cite this page

    UCLA OIT
    1. © 2021 UC REGENTS
    2. HOME
    3. CONTACT