* ********************************************** * Summary Note by Jing Li and Junsoo Lee * panel_2.do * * Commands: xtdata (II), xtcloglog, xtgee, * xtlogit, xtprobit, xtsum & xttab, * xttobit, xtpcse, xtregar, xtintreg, * xtrchh, xtfrontier, xthtaylor * September 2003 * *********************************************** clear set mem 200m cd "C:\UpCD1\WORK\Stata\" log using panel_2.log, replace set more off set matsize 800 ********************************* * xtdata * ********************************* use xtdatasmpl.dta,clear * use http://www.stata-press.com/data/r8/xtdatasmpl, clear ** 1. use "xtdata" to convert the data into a form suitable for between estimation xtdata ln_w grade age* ttl_exp* tenure* black not_smsa south, be clear regress ln_w grade age* ttl_exp* tenure* black not_smsa south * compare the above results to those from using "xtreg, be" xtreg ln_w grade age* ttl_exp* tenure* black not_smsa south, be ** use "xtdata" to convert the data into a form suitable for fixed-effects(within) estimation use xtdatasmpl.dta,clear xtdata ln_w grade age* ttl_exp* tenure* black not_smsa south, fe i(idcode) clear regress ln_w grade age* ttl_exp* tenure* black not_smsa south * compare the above results to those from using "xtreg, fe" xtreg ln_w grade age* ttl_exp* tenure* black not_smsa south, fe i(idcode) ** use "xtdata" to convert the data into a form suitable for random-effects estimation use xtdatasmpl.dta,clear ** ratio is specified to be 1; this is for specification-search purposes only xtdata ln_w grade age* ttl_exp* tenure* black not_smsa south, re ratio(1) clear regress ln_w grade age* ttl_exp* tenure* black not_smsa south constant, nocons * compare the above results to those from using "xtreg, re" xtreg ln_w grade age* ttl_exp* tenure* black not_smsa south, re ** note: every time before using "xtdata", you have to use the original data. ********************************* * xtcloglog * ********************************* ** 2. try the command 'xtcloglog' *webuse union.dta,clear *save union.dta use union.dta, clear * use http://www.stata-press.com/data/r8/union, clear iis idcode tis year * There is no FE version of this model; a conditional likelihood function cannot be defined. ** random-effects model xtcloglog union age grade not_smsa south southXt, re xtcloglog union age grade not_smsa south southXt, re quad(20) ** population-averaged model (xtgee) xtcloglog union age grade not_smsa south southXt, pa ** population-averaged model with robust variance, clustering on 'i' xtcloglog union age grade not_smsa south southXt, pa i(idcode) robust ** population-averaged model with 'xtgee' options xtcloglog union age grade not_smsa south southXt, pa corr(exchangeable) ********************************* * xtgee * ********************************* * Population Averaged model (generalized linear model or Generalized Estimating Equations (GEEs)) * g[E(y(it)] = X(it)*b with y ~ specific dist. * * e.g., If logit[E(y(it)] = X(it)*b with y ~ Bernoulli, it's a logit model. * Then, use link(logit), family(binomial) * * There is no convenient likelihood function. (Need to read more references.) * * This procedure allows to specify the within-group correlation structure for the panels. * default: equal-correlation, corr(exchangeable) * corr(ar1) can be estimated. No option for psar1. * "xtcorr" gives the within=group correlations. * Note : xtgls can allow for cross-sectional correlation across panels, but this option is not * available in xtgee. Instead, xtgls does not allow for the within-group correlation (except * for autocorrelation with ar1 or psar1), but xtgee can allow for it. * Special cases (with balanced panels): Try these.. I have not compared them yet. * * xtgee, corr(independent) link(cloglog) => cloglog or xtcloglog * xtgee, corr(independent) link(probit) => probit (but std errors are different) * If the binomial denominator is not 1, it's bprobit. * Further Note: blogit and bprobit produce maximum-likelihood logit and probit estimates on grouped ("blocked") data; * glogit and gprobit produce weighted least-squares estimates. * xtgee with negative binomial (nbinomial) produces estimates conditional on alpha (correlation). * nbreg gives unconditional estimates. * xtgee with corr(independent) fits exponential regression (as in survival models) but * not with censored data. * * xtgee, fam(gauss) link(iden) corr(exch) => xtreg, re or xtreg, mle use union.dta,clear * use http://www.stata-press.com/data/r8/union, clear iis idcode tis year xtgee union age grade not_smsa south southXt, family(gamma) link(log) corr(exchangeable) robust xtgee union age grade not_smsa south southXt, family(poisson) link(log) corr(unstructured) xtgee union age grade not_smsa south southXt, family(poisson) link(identity) corr(unstructured) use nlswork2.dta, clear * use http://www.stata-press.com/data/r8/nlswork2, clear *webuse nlswork2.dta,clear *save nlswork2.dta iis idcode tis year gen age2 = age*age gen ttl_exp2 = ttl_exp*ttl_exp gen tenure2 = tenure^2 ** compare the results from 'regress' and 'xtgee' (using OLS) regress ln_w grade age* ttl_exp* tenure* xtgee ln_w grade age* ttl_exp* tenure*, corr(indep) nmp xtgee ln_w grade age* ttl_exp* tenure*, corr(ar1) nmp xtgee ln_w grade age* ttl_exp* tenure*, fam(gamm) corr(indep) nmp xtgee ln_w grade age* ttl_exp* tenure*, fam(gamm) corr(ar2) xtgee ln_w grade age* ttl_exp* tenure*, fam(poisson) link(log) corr(unstructured) xtgee ln_w grade age* ttl_exp* tenure*, fam(poisson) link(log) corr(stationary 2) use airacc.dta, clear * use http://www.stata-press.com/data/r8/airacc, clear *webuse airacc.dta,clear *save airacc.dta iis(airline) tis(time) gen lnpm = ln(pmiles) xtgee i_cnt inprog, family(poisson) eform offset(lnpm) xtgee i_cnt inprog, family(gauss) corr(exchangeable) eform offset(lnpm) xtgee i_cnt inprog, family(binomial) link(identity) corr(independent) eform offset(lnpm) xtgee i_cnt inprog, family(igaussian) link(log) corr(unstructured) ** xtgee i_cnt inprog, family(binomial) link(logit) corr(exchangeable) /* this line does not work, error message: estimates diverging (missing predictions)*/ xtgee i_cnt inprog, family(gamma) link(reciprocal) corr(independent) xtgee i_cnt inprog, family(gauss) link(identity) corr(independent) rgf trace robust score(newscore1) xtgee i_cnt inprog, family(gauss) link(power) robust xtgee i_cnt inprog, family(gauss) link(power) t(time) corr(stationary 2) robust ********************************* * xtlogit * ********************************* use union.dta, clear * use http://www.stata-press.com/data/r8/union, clear iis idcode tis year ** random-effects model xtlogit union age grade not_smsa south southXt, re quadchk * # of points to use in the quadrature approximation of the integral (this checkup is important.) xtlogit union age grade not_smsa south southXt, re offset(age) * the coeff of age = 1 (restricted) ** conditional fixed-effects model xtlogit union age grade not_smsa south southXt, fe nolog xtlogit union age grade not_smsa south southXt, fe noskip xtlogit union age grade not_smsa south southXt, fe offset(grade) nolog ** population-averaged model xtlogit union age grade not_smsa south southXt, pa eform xtlogit union age grade not_smsa south southXt, pa robust * Huber & White sandwich estimator of variance xtlogit union age grade not_smsa south southXt, pa offset(grade) eform xtlogit union age grade not_smsa south southXt, pa offset(grade) robust xtlogit union age grade not_smsa south southXt, pa nolog or robust /* "or" the estimated coefficients are transformed to odds ratios: i.e., exp(b) is reported. */ xtlogit union age grade not_smsa south southXt, pa nolog robust ** compare the results to 'xtgee' xtgee union age grade not_smsa south southXt, nolog robust family(binomial) link(logit) corr(exchangeable) ********************************* * xtprobit * ********************************* * There is no FE model for this. One may ne tempted to use probit using dummy variables, * but the resulting estimator is biased. use union.dta,clear * use http://www.stata-press.com/data/r8/union, clear iis idcode tis year ** random-effects model xtprobit union age grade not_smsa south southXt, re nolog quadchk * # of points to use in the quadrature approximation of the integral (this checkup is important.) xtprobit union age grade not_smsa south southXt in 1/25000, re offset(age) xtprobit union age grade not_smsa south southXt, re offset(grade) nolog ** population-averaged model xtprobit union age grade not_smsa south southXt, pa xtprobit union age grade not_smsa south southXt, pa eform xtprobit union age grade not_smsa south southXt, pa robust xtprobit union age grade not_smsa south southXt, pa robust nolog /* first use 'xtprobit' */ ** compare the results to 'xtgee' xtgee union age grade not_smsa south southXt, family(binomial) link(probit) corr(exchangeable) robust nolog *webuse chicken.dta,clear *save chicken.dta use chicken.dta,clear * use http://www.stata-press.com/data/r8/chicken, clear iis(person) ** random-effects model xtprobit complain age grade south tenure gender race income genderm burger chicken, re nolog xtprobit complain age grade south tenure gender race income genderm burger chicken, re ** population-averaged model xtprobit complain age grade south tenure gender race income genderm burger chicken, pa xtprobit complain age grade south tenure gender race income genderm burger chicken, pa eform xtprobit complain age grade south tenure gender race income genderm burger chicken, pa robust **************************** * xtsum & xttab * **************************** use nlswork.dta, clear iis idcode tis year xtsum age grade ttl_exp hours ln_wage xttab union xttrans union **************************** * xttobit * **************************** * Again, no FE version in stata, as there is no conditional likelihood function. * Honore(1992)'s semi-parametric FE Tobit version can be considered, but * unconditional tobit FE with dummies is biased. * ll (lower limit) and ul (upper limit) * option "tobit" reports the LR stat. versus pooling tobit. *webuse nlswork.dta,clear *save nlswork.dta use nlswork.dta, clear * use http://www.stata-press.com/data/r8/chicken, clear iis idcode tis year ** random-effects model (censoring point is ln_wage no greater than 1.9) xttobit ln_wage union age grade not_smsa south occ_code, ul(1.9) tobit quadchk, nooutput ** random-effects model (censoring point is ln_wage lies between 0.9 and 1.9) xttobit ln_wage union age grade not_smsa south occ_code, ll(0.9) ul(1.9) tobit quadchk, nooutput ** random-effects model (quadrature approx. of the integral is at its max, i.e. 30) xttobit ln_wage union age grade not_smsa south occ_code, ll(0.9) ul(1.9) quad(30) tobit ** random-effects model (the coefficient of tenure constrained to be 1) xttobit ln_wage union age grade tenure ttl_exp race not_smsa south occ_code, ll(0.4) offset(tenure) tobit ** random-effects model (the coefficient of ttl_exp constrained to be 1) xttobit ln_wage union age grade tenure ttl_exp race not_smsa south occ_code, ul(1.6) offset(ttl_exp) tobit **************************** * xtpcse * **************************** * Alternative to xlgls * Panel-corrected std error (PCSE) when OLS or Prais-Winsten regression was used. * The disturbances are assumed to be heteroskedastic and contemporaneously correlated across panels. * Also, options include corr(indep), corr(ar1), and corr(psar1), which has panel specific ar(1) errors. * Consistent as T goes infinity. * Again, this does not include within-group correlations; for this, use xtgee (Consistent as N goes infinity). use grunfeld.dta,clear * use http://www.stata-press.com/data/r8/grunfeld, clear tsset company year, yearly xtpcse invest mvalue kstock xtpcse invest mvalue kstock, correlation(ar1) xtpcse invest mvalue kstock, correlation(psar1) rhotype(tscorr) detail **************************** * xtregar * **************************** * FE and RE models with AR(1) error (common rho only). tsset is needed due to T asymptotics. * Can accomodate unbalanced panerls. * "lbi" option reports the LBI statistic for rho = 0. use grunfeld.dta,clear * use http://www.stata-press.com/data/r8/grunfeld, clear tsset company year, yearly ** fixed-effects with an AR(1) disturbance xtregar invest mvalue kstock, fe rhotype(tscorr) xtregar invest mvalue kstock, fe rhotype(tscorr) twostep xtregar invest mvalue kstock if year != 1943 & year != 1944, fe lbi ** random-effects with an AR(1) disturbance xtregar invest mvalue kstock, re rhotype(tscorr) xtregar invest mvalue kstock if year != 1943 & year != 1944, re lbi **************************** * xtintreg * **************************** * RE models for interval data panels (no FE version) * needs Dep(lower) and Dep(upper), and RE version requires a quadchk checkup. * Prediction can be given over intervals. * pr0(a,b) computes P(20 < y < 30). * intreg computes the LR test for the OLS *webuse nlswork3.dta,clear *save nlswork3.dta use nlswork3.dta, clear * use http://www.stata-press.com/data/r8/grunfeld, clear iis idcode tis year ** random-effects interval data regression model xtintreg ln_wage1 ln_wage2 union age grade not_smsa south southXt occ_code, noskip intreg predict new_var, pr0(1,3) predict new_var1, pr0(0,3) ** the coefficient of age constrained to be 1 *xtintreg ln_wage1 ln_wage2 union age grade not_smsa south southXt occ_code, quad(25) offset(age) intreg *xtintreg ln_wage1 ln_wage2 union age grade tenure ttl_exp not_smsa south, offset(tenure) intreg *xtintreg ln_wage1 ln_wage2 union age grade not_smsa south southXt occ_code, offset(grade) quad(20) intreg **************************** * xtpoisson * **************************** * Three models: FE, RE and GEE * Note that there is no prediction for the FE model: conditional likelihood function. * "irr" reports exp(b), which implies incidence-rate ratios *webuse ships.dta,clear *save ships.dta use ships.dta,clear * use http://www.stata-press.com/data/r8/ships, clear ** random-effects model xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, re i(ship) xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, re i(ship) irr xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, re i(ship) exposure(service) irr xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, re i(ship) ex(service) irr normal nolog * RE has a normal distribution, rather than a gamma dist. xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, re i(ship) ex(service) irr normal quad(25) ** conditional fixed-effects model xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, fe i(ship) xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, fe i(ship) ex(service) xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, fe i(ship) ex(service) irr ** population-averaged model ('eform' is an xtgee option) xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, pa i(ship) ex(service) robust xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, pa i(ship) ex(service) eform xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, pa i(ship) ex(service) robust eform **************************** * xtnbreg * **************************** * Negative binomial Poisson models (RE, GEE and FE versions) * Again, no prediction for the FE version use airacc.dta,clear * use http://www.stata-press.com/data/r8/airacc, clear iis airline tis time ** random-effects model xtnbreg i_cnt inprog, re exposure(pmiles) irr predict new_var2 ** conditional fixed-effects model xtnbreg i_cnt inprog, fe exposure(pmiles) irr predict new_var3 ** population-averaged model ('eform' is an xtgee option) xtnbreg i_cnt inprog, pa exposure(pmiles) robust eform **************************** * xtrchh * **************************** * Hildreth-Houck random coefficient model use invest2.dta,clear * use http://www.stata-press.com/data/r8/invest2, clear * Check the data for possible random coefficients reshape wide invest market stock, i(time) j(company) sureg (invest1 market1 stock1) (invest2 market2 stock2) (invest3 market3 stock3) (invest4 market4 stock4) (invest5 market5 stock5) use invest2.dta,clear xtrchh invest market stock, i(company) t(time) predict new4, xb **************************** * xtfrontier * **************************** *Frontier Models *Battese-Coelli (1992) parameterization fof time effects multipleid by the inefficienty term. *webuse xtfrontier1.dta,clear *save xtfrontier1.dta use xtfrontier1.dta,clear * use http://www.stata-press.com/data/r8/xtfrontier1, clear ** time-invariant model xtfrontier lnwidgets lnmachines lnworkers, ti i(id) xtfrontier lnwidgets machines workers, ti i(id) nodifficult ** time-invariant model in terms of a cost function xtfrontier lnwidgets lnmachines lnworkers, ti i(id) cost xtfrontier lnwidgets machines workers, ti i(id) nodifficult cost ** time-invariant model with constraint constraint define 1 _b[lnmachines] + _b[lnworkers] = 1 xtfrontier lnwidgets lnmachines lnworkers, ti i(id) constraint(1) xtfrontier lnwidgets lnmachines lnworkers, ti i(id) constraint(1) cost constraint define 2 _b[lnmachines] = _b[lnworkers] xtfrontier lnwidgets lnmachines lnworkers, ti i(id) constraint(2) xtfrontier lnwidgets lnmachines lnworkers, ti i(id) constraint(2) cost ** time-varying decay model xtfrontier lnwidgets lnmachines lnworkers, tvd i(id) t(t) ** time-varying decay model in terms of a cost function xtfrontier lnwidgets lnmachines lnworkers, tvd i(id) t(t) cost xtfrontier lnwidgets machines workers, tvd i(id) t(t) cost ** time-varying decay model with constraint constraint define 3 _b[lnmachines] = 2* _b[lnworkers] xtfrontier lnwidgets lnmachines lnworkers, tvd i(id) t(t) constraint(3) xtfrontier lnwidgets lnmachines lnworkers, tvd i(id) t(t) constraint(3) cost **************************** * xthtaylor * **************************** *webuse xthtaylor1.dta,clear *save xthtaylor1.dta * use http://www.stata-press.com/data/r8/xthtaylor1, clear use xthtaylor1.dta, clear ** Hausman-taylor estimator with only endogenous variables correlate ui z1 z2 x1a x1b x2 eit xthtaylor yit x1a x1b x2 z1 z2, endog(x2 z2) i(id) xthtaylor yit x1a x1b x2 z1 z2, endog(x2 z2) i(id) t(t) amacurdy xthtaylor yit x1a x1b x2 z1 z2, endog(x2 z2) i(id) t(t) small xthtaylor yit x1a x1b x2 z1 z2, endog(x2 z2) i(id) t(t) amacurdy small ** Hausman-taylor estimator with constant variables xthtaylor yit x1a x1b x2 z1 z2 ui, endog(x2 z2) constant(z1 z2 ui) i(id) xthtaylor yit x1a x1b x2 z1 z2 ui, endog(x2 z2) constant(z1 z2 ui) i(id) t(t) amacurdy xthtaylor yit x1a x1b x2 z1 z2 ui, endog(x2 z2) constant(z1 z2 ui) i(id) t(t) small ** Hausman-taylor estimator with varying variables xthtaylor yit x1a x1b x2 z1 z2 ui, endog(x2 z2) varying(x2 x1a x1b) i(id) xthtaylor yit x1a x1b x2 z1 z2 ui, endog(x2 z2) varying(x2 x1a x1b) i(id) t(t) amacurdy xthtaylor yit x1a x1b x2 z1 z2 ui, endog(x2 z2) varying(x2 x1a x1b) i(id) t(t) small *webuse psidextract.dta,clear *save psidextract.dta * use http://www.stata-press.com/data/r8/psidextract, clear use psidextract.dta,clear iis id tis t xtsum exp exp2 wks ms union, i(id) ** Hausman-taylor estimator with only endogenous variables correlate fem blk occ south smsa ind ed xthtaylor lwage occ south smsa ind exp exp2 wks ms union fem blk ed, endog(exp exp2 wks ms union ed) xthtaylor lwage occ south smsa ind exp* wks ms union fem blk ed, endog(exp exp2 wks ms union ed) amacurdy xthtaylor lwage occ south smsa ind exp* wks ms union fem blk ed, endog(exp exp2 wks ms union ed) small xthtaylor lwage occ south smsa ind exp* wks ms union fem blk ed, endog(exp exp2 wks ms union ed) amacurdy small ** Hausman-taylor estimator with constant variables xthtaylor lwage occ south smsa ind exp exp2 wks ms union fem blk ed, endog(exp exp2 wks ms union ed) /* */ constant(fem blk ed) xthtaylor lwage occ south smsa ind exp exp2 wks ms union fem blk ed, endog(exp exp2 wks ms union ed) /* */ constant(fem blk ed) amacurdy xthtaylor lwage occ south smsa ind exp exp2 wks ms union fem blk ed, endog(exp exp2 wks ms union ed) /* */ constant(fem blk ed) small ** Hausman-taylor estimator with varying variables xthtaylor lwage occ south smsa ind exp exp2 wks ms union fem blk ed, endog(exp exp2 wks ms union ed) /* */ varying(ms exp* occ south smsa ind wks union) xthtaylor lwage occ south smsa ind exp exp2 wks ms union fem blk ed, endog(exp exp2 wks ms union ed) /* */ varying(ms exp* occ south smsa ind wks union) amacurdy xthtaylor lwage occ south smsa ind exp exp2 wks ms union fem blk ed, endog(exp exp2 wks ms union ed) /* */ varying(ms exp* occ south smsa ind wks union) small