*Open the log file; the path and name of the files are specific to your computer; log using "C:\Documents and Settings\student\Desktop\Lab1\lab1.log" infile week1-week9 using "C:\Documents and Settings\student\Desktop\Lab1\pigs.raw" browse save "C:\Documents and Settings\student\Desktop\Lab1\pigs.dta" clear all use "C:\Documents and Settings\student\Desktop\Lab1\pigs.stata.dta", clear edit clear all use "C:\Documents and Settings\student\Desktop\Lab1\pigs.dta" edit *Genearate the id=observation number generate id=_n move id week1 list list 1/5 list in 1/5 describe save "C:\Documents and Settings\student\Desktop\Lab1\pigs.dta", replace *reshape the dataset into long format; reshape long week, i(id) j(visit) sort id visit list in 1/5 * Plot in fig3.1 in DHLZ twoway line week visit, s(i) *To obtain Fig3.2 in DHLZ: reshape wide *One way of generating the standardized weight summarize week1 gen sweek1=(week1-25.02)/2.47 * A simpler way: egen sweek1=std(week1) egen sweek2=std(week2) egen sweek3=std(week3) egen sweek4=std(week4) egen sweek5=std(week5) egen sweek6=std(week6) egen sweek7=std(week7) egen sweek8=std(week8) egen sweek9=std(week9) reshape long week sweek, i(id) j(visit) sort id visit twoway line sweek visit, s(i) *Linear regression; regress week visit *Close the log file log close exit, clear