UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

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 "findit spagplot")
spagplot alcuse age_14 , id( id ) 
Here we make the same graph manually.
use http://www.ats.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
But say that you wanted to see separate lines for males and females.  We can
do that, as shown below.
use http://www.ats.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


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California