* MLM 656: Midterm Solutions * load birthwt.dta * cd "C:\Documents and Settings\Sandrah Eckel\My Documents\School\Term 4 2008\MLM\midterm exam" use birthwt.dta, clear set more off ** PART I: EDA codebook label var age "Mother's Age" label var birthorder "Birth Order" label var birthwt "Infant's Birth Weight (grams)" * no missing data * * how many mothers and children/mother? * xtset mother birthorder xtdes * max/min age of delivery for mothers * codebook age codebook age if birthorder==1 * generate a rough interpregnancy interval variable sort mother age by mother: gen agelag1 =age[_n-1] gen interval = age - agelag1 label var interval "Interpregnancy Interval" drop agelag1 codebook interval summ interval * look at the marginal relation between mother's age and birthweight * lowess birthwt age, bw(0.5) * look at the marginal relation between birthorder and birthweight * graph box birthwt, over(birthorder) title(Birth Order) * look at the marginal relation between interval and birthweight * graph box birthwt, over(interval) title(Interpregnancy Interval) lowess birthwt interval, bw(0.5) ** PART II: Variance components model with no covariates * variance components model * xtmixed birthwt || mother:, mle xtreg birthwt, i(mother) mle * generate a variable containing overall mean birthweight * egen meanbw = mean(birthwt) * generate a variable containing the mother-specific mean birthweight * sort mother by mother: egen mothermeanbw = mean(birthwt) * generate a variable containing the mother-specific fitted (fixed + RI) mean birthweight * quietly xtmixed birthwt || mother:, mle predict fitmothermeanbw, fitted * assess the normality assumptions * predict ebri, reffects predict resid, residuals hist ebri, normal hist resid, normal ** PART III: Random Intercept models with covariates xtmixed birthwt age interval|| mother:, mle nolog ** random coefficient on interval at the mother level ** xtmixed birthwt age interval|| mother: interval, cov(unstruct) mle nolog predict ebcoef ebri, reffects hist ebcoef, norm freq ** list the 5 mothers with largest EB estimates of the random coef sort ebcoef list mother ebcoef in -25/L if birthorder==1