log using ht,replace use phuz,clear sort id replace y=log(y) gen exp=yr-phd gen expsq=exp^2 gen ier=1/(exp*rphd) gen d70=0 replace d70=1 if phd>70 quietly by id: gen y1=y[_n-1] quietly by id: gen y2=y[_n-2] drop if y2==. * Why can't we ommitt the above command? * Stata can handle missing obs, but here we will * have problems if we let Stata do our work. Why? PQ exp PQ expsq PQ ier PQ y PQ y1 PQ y2 PQ d70 PQ sex * Note that Pd70=d70, Psex=sex, Qd70=0, Qsex=0. * Nonetheless, we need Pd70 and Psex latter. * Can you see where and why? regress y y1 y2 exp expsq ier d70 sex (Qy1 Qy2 Qier Pexp Qexp Pexpsq Qexpsq d70 sex) predict r,res PQ r gen Prsq=Pr^2 quietly by id: gen mark=_n * What does mark do? (see the next regression) quietly by id: gen T=_N gen iT=1/T regress Prsq iT if mark==1 matrix b=get(_b) gen theta=sqrt(_b[iT]/(_b[iT]+_b[_cons]*T)) replace y=y-(1-theta)*Py replace y1=y1-(1-theta)*Py1 replace y2=y2-(1-theta)*Py2 replace exp=exp-(1-theta)*Pexp replace expsq=expsq-(1-theta)*Pexpsq replace ier=ier-(1-theta)*Pier replace d70=d70-(1-theta)*Pd70 replace sex=sex-(1-theta)*Psex regress y y1 y2 exp expsq ier d70 sex theta (Qy1 Qy2 Qier Pexp Qexp Pexpsq Qexpsq Pd70 Psex theta),noconst * Why do we have theta as a variable and no intercept here? matrix list b summarize theta log close