********************************************************************** ********************************************************************** **** **** **** chap6.do - Testing **** **** **** **** Stata do file to reproduce examples **** **** in Chapter 6 of **** **** Snijders, Tom A.B., and Bosker, Roel J. **** **** Multilevel Analysis: **** **** An Introduction to Basic and Advanced Multilevel Modeling,**** **** second edition **** **** London etc.: Sage Publishers, 2012 **** **** **** **** Contributed by Jon Fahlander and Tim Mueller **** **** **** **** **** ********************************************************************** ********************************************************************** ** Example 6.1 ** ** Hypothesis testing ** capture log close log using "J:\Multilevel\Chp6_Hypothesis_testing.log", replace clear all set more off cd "J:\Multilevel TA" *Read in the data *infile schoolnr pupilNR_new langpost ses IQ_verb sex Minority denomina sch_ses sch_iqv sch_min using mlbook2_r.txt use mlbook2_r.dta, clear *Example 6.1 egen gmeanIQverb = mean(IQ_verb), by(schoolnr) egen gmeanSES = mean(ses), by(schoolnr) *Model 1 xtmixed langpost IQ_verb ses gmeanIQverb || schoolnr : IQ_verb , mle covariance(un) var est store mod1 estat ic *Model 2 gen IQverb_tilde = IQ_verb- gmeanIQverb xtmixed langpost ses IQverb_tilde gmeanIQverb || schoolnr : IQ_verb , mle covariance(un) var est store mod2 estat ic esttab mod1 mod2, se wide nostar /// transform(ln*: exp(2*@) exp(2*@) at*: tanh(@) (1-tanh(@)^2)) /// eqlabels("" "var(u1)" "var(u0)" "corr(u1,_cons)" "var(Residual)", none) /// varlabels(,elist(weight:_cons "{break}{hline @width}")) /// varwidth(16) /*Note: esttab is an ado that creates regression tables. If you want to know more, look up estout and esttab. There is also a possibility to export these tables to LateX. Check out this web page: http://repec.org/bocode/e/estout/advanced.html*/ *Test for random intercepts regr langpost IQ_verb estat ic dis -2*-12675.49 *25350.98 xtmixed langpost IQ_verb || schoolnr:, var mle estat ic dis -2*-12456.08 *24912.16 /*Difference in deviance is 438.81. Note the bottom of the output! Compare page 99!*/ *Test for random slopes xtmixed langpost IQ_verb || schoolnr:, var mle est store XT1 xtmixed langpost IQ_verb || schoolnr: IQ_verb, var mle cov(unstr) est store XT2 lrtest XT2 XT1 *Wald test for categorical variables *Assume you are including a set of dummy variables. This test will check, whether all of them are jointly 0. xtmixed langpost i.denomina || schoolnr:, var mle testparm i.denomina *Test whether the effects of different categories of the set of dummies are different from each other. *In the denomination example: category 2 is Catholic schools, category 3 is Protestant schools. *Do those two schooltypes differ in their language scores? . lincom _b[2.denomina]-_b[3.denomina] capture log close