Docsity

Análisis multinivel usando stata, Diapositivas de Econometría

Vista previa parcial del texto

¡Descarga Análisis multinivel usando stata y más Diapositivas en PDF de Econometría solo en Docsity!

Análisis multinivel

(ver. 1.0)

Oscar Torres-Reyna

Data Consultant

[email protected]

http://dss.princeton.edu/training/

Traducción: CASTILLO M.

2

Utilice el modelo multinivel siempre que sus datos estén agrupados (o

anidados) en más de una categoría (por ejemplo, estados, países, etc.)

Los modelos multinivel permiten:

  • Efectos de estudio que varían por entidad (o grupos)
  • Estimar los promedios de nivel de grupo

Algunas ventajas:

  • La regresión regular ignora la variación promedio entre entidades.
  • La regresión individual puede enfrentar problemas de muestra y falta

de generalización.

Motivación

4

statsby inter=_b[_cons] slope=_b[x1], by(school) saving(ols, replace): regress y
x
sort school
merge school using ols
drop _merge
gen yhat_ols = inter + slope*x
sort school x
separate y, by(school)
separate yhat_ols, by(school)
twoway connected yhat_ols1-yhat_ols65 x1 || lfit y x1 , clwidth(thick) clcolor(black)
legend(off) ytitle(y)

-^2 0 -^1 0 0 10 20 30 y

  • 40 - 20 20 40 0 Reading test Regresiones individuales (enfoque de no agrupación)
LR test vs. linear regression: chibar2(01) = 498.72 Prob >= chibar2 = 0.
sd(Residual) 9.207357 .1030214 9.007636 9.
sd(_cons) 4.106553 .3999163 3.392995 4.
school: Identity
Random-effects Parameters Estimate Std. Err. [95% Conf. Interval]
_cons - .1317104 .536272 - 0.2 5 0.80 6.
y Coef. Std. Err. z P>|z| [95% Conf.
Interval]
Log likelihood = - 14851.
Wald chi2( 0 )
Prob > chi
Obs per group: min^ =
avg =
max =
Mixed-effects ML regression
Group vari able: school
Number of obs
Number of groups
. xtmixed y || school: , mle nolog

Desviación estándar a nivel escolar (nivel 2) Desviación estándar a nivel individual (nivel 2) Media de intercepciones a nivel estatal

( sigma _ u )^2  ( sigma _ e )^2 sd (_ cons )^2  sd ( residual )^2 4.11^2 9.21^2
( sigma _ u )^2 sd (_ cons )^2 4.1 12
Intraclase _ correlación 

Modelo de intercepción variable (nulo) (^) y i ^ ^ j [ i ] ^  i Ho: efectos aleatorios = 0 NOTA: Stata 13, el comando cambió a "mixed" Si la correlación interclase (IC) se acerca a 0, entonces la agrupación por condados (o entidades) no sirve de nada (también puede ejecutar una regresión simple). Si el IC se acerca a 1, entonces no hay ninguna variación para explicar a nivel individual, todos son iguales.. 5 “Una correlación intraclase le informa sobre la correlación de las observaciones (casos) dentro de un grupo” (http://www.ats.ucla.edu/stat/Stata/Library/cpsu.htm) (^) PU/DSS/OTR

7 Desviación estándar a nivel escolar (nivel 2 ) Desviación estándar a nivel individual (nivel 2) Media de intercepciones a nivel estatal

( sigma _ u )^2 sd (_ cons )^2  sd ( x 1) 0.12^2 3.01^2
Intraclase _ correlación     0.
( sigma _ u )^2  ( sigma _ e )^2 sd (_ cons )^2  sd ( x 1)  sd ( residual )^2 0.12^2  3.01^2  7.44^2

Intercepción variable, modelo de coeficiente variable. LR test vs. linear regression: chi2( 3 ) = 443.64 Prob > chi2 = 0. Note: LR test is conservative and provided only for reference. Random-effects Parameters Estimate Std. Err. [95% Conf. Interval] school: Unstructured sd(x1) sd(_cons) corr(x1,_cons )

sd(Residual) 7.44078 8 .0839482 7.278059 7.60715 7 y Coef. Std. Err. z P>|z| [95% Conf. Interval] x 1 .556729 1 .0199367 27.9 2 0.000 .5176539 .595804 3 _cons - .115084 1 .3978336 - 0.2 9 0.772 - .8948236 .664655 4 Wald chi2( 1 ) = 779.8 0 Log likelihood = - 14004.61 3 Prob > chi2 = 0.000 0 Obs per group: min = avg = max =

Mixed-effects ML regression Number of obs = 4059 Group vari able: school Number of groups = 65

. xtmixed y x1 || school: x1, mle nolog covariance(unstructure) yi   (^) j [ i ]   (^) j [ i ] xi   i Ho: efectos aleatorios = 0

8 Desviación estándar a nivel escolar (nivel 2) Desviación estándar a nivel individual (nivel 2) Media de intercepciones a nivel estatal Modelo de pendiente variable LR test vs. linear regression: chibar2(01) = 0.00 Prob >= chibar2 = 1. sd(Residual) 8.052417 .089372 7.879142 8. sd(R.x1) .0003388 .1806391 0. _all: Identity Random-effects Parameters Estimate Std. Err. [95% Conf. Interval] x 1 _cons

y Coef. Std. Err. z P>|z| [95% Conf. .

-. Interval] Log likelihood = - 14226. Wald chi2( 1 ) Prob > chi

Obs per group: min = avg = max =

Mixed-effects ML regression Group vari able: _all Number of obs Number of groups

. xtmixed y x1 || _all: R.x1, mle nolog yi     (^) j [ i ] xi   i

10 Comparando modelos usando la prueba de cociente de probabilidad Note: LR test is conservative Likelihood-ratio test (Assumption: ri nested in rc) LR chi2( 2 ) = Prob > chi2 = 40.3 7 0.000 0 Use la prueba de razón de verosimilitud (lrtest) para comparar modelos ajustados por máxima verosimilitud. Esta prueba compara la "probabilidad de registro" (que se muestra en la salida) de dos modelos y prueba si son significativamente diferentes. /Fitting random intercepts and storing results/ quietly xtmixed y x1 || school: , mle nolog estimates store ri /Fitting random coefficients and storing results/ quietly xtmixed y x1 || school: x1 , mle nolog covariance(unstructure) estimates store rc /Running the likelihood-ratio test to compare/ lrtest ri rc

. lrtest ri rc La hipótesis nula es que no hay una diferencia significativa entre los dos modelos. Si Prob>chi2<0.05 entonces puede rechazar el nulo y concluir que existe una diferencia estadísticamente significativa entre los modelos. En el ejemplo anterior, rechazamos el nulo y concluimos que el modelo de coeficientes aleatorios proporciona un mejor ajuste (tiene la menor probabilidad de registro)

11 Desviación estándar a nivel individual (nivel 2) Media de intercepciones a nivel estatal

( sigma _ u )  ( sigma _ e ) var(_ cons )^2  var( x 1)  var( residual ) 0.014  9.045  55.
( sigma _ u ) var(_ cons )  var( x 1)
Intraclase _ correlación 

Intercepción variable, modelo de coeficiente variable: postestimación LR test vs. linear regression: chi2( 3 ) = 443.64 Prob > chi2 = 0. Note: LR test is conservative and provided only for reference. Random-effects Parameters Estimate Std. Err. [95% Conf. Interval] school: Unstructured var(x1) var(_cons) cov(x1,_cons)

var(Residual) 55.3653 3 1.249282 52.97014 57.8688 3 y Coef. Std. Err. z P>|z| [95% Conf. Interval] x 1 .556729 1 .0199367 27.9 2 0.000 .5176539 .595804 3 _cons - .115084 1 .3978336 - 0.2 9 0.772 - .8948236 .664655 4 Desviación estándar a nivel escolar (nivel 2) Wald chi2( 1 ) = 779.8 0 Log likelihood = - 14004.61 3 Prob > chi2 = 0.000 0 Obs per group: min = avg = max =

Mixed-effects ML regression Number of obs = 4059 Group vari able: school Number of groups = 65

. xtmixed y x1 || school: x1, mle nolog covariance(unstructure) variance

13 Postestimación: estimación de efectos aleatorios (errores a nivel de grupo)

predict u* , reffects

Se crean dos nuevas variables.

u1 “BLUP r.e. for school: x1” ------- /* uβ */

u2 “BLUP r.e. for school: _cons” --- /* uα */

yi   (^) j [ i ]   (^) j [ i ] xi   i^ ^ u  ^ u    i i j [ i ] yi   (^) j [ i ]   (^) j [ i ] xi Efectos fijos Efectos aleatorios

Para estimar los efectos aleatorios u, use el comando predict con los reffects, de

la opción, esto le dará las mejores predicciones no lineales lineales (BLUP) de

los efectos aleatorios que básicamente muestran la cantidad de variación tanto

para la intersección como para el coeficiente beta estimado (s ). Después de

ejecutar xtmixed, escriba

Postestimación: estimación de efectos aleatorios (errores a nivel de grupo)

yi  0.12 0.56 x 1 yi  0.12  0.56 x 1  u   u 

Efectos fijos Efectos aleatorios Para explorar algún tipo de resultados. : bysort _school: generate groups=(n==1) /*_n==1 selects the first case of each group */

school u 2 u 1 1 3.74933 6 .124975 5 2 4.70212 9 .164726 1 3 4.7976 8 .080866 6 4 .350250 5 .127182 1 5 2.46280 5 .072057 6 6 5.18380 9 .058624 2 7 3.64094 2 - .148869 7 8 - .12188 6 .006885 5 9 - 1.76798 2 - .088619 4 10 - 3.13907 6 - .136076 3 list school u2 u1 if school<=10 & groups

. list school u2 u1 if school<=10 & groups

Aquí u2 y u1 son los errores de nivel de

grupo para la intersección y la pendiente,

respectivamente. Para la primera escuela

la ecuación sería:

y 1  0.12  0.56 x 1  3.75  0.12  (0.12  3.75)  (0.56  0.12) x 1  3.63  0.68 x 1 14

16 Postestimación: valores de ajuste

Usando intersección y pendiente puedes estimar yhat, escriba

gen yhat= intercept + (slope*x1)

O, después de xtmixed escriba:

predict yhat_fit , fitted

list school yhat yhat_fit if school<=10 & groups

school yhat yhat_fit 1 - 12.4294 3 - 12.4294 3 2 - 15.395 1 - 15.395 1 3 - 7.17987 1 - 7.17987 1 4 - 15.8805 2 - 15.8805 2 5 - 5.19331 7 - 5.19331 8 6 - 3.83666 8 - 3.83666 7 7 - 6.08493 9 - 6.08493 9 8 - 13.9835 3 - 13.9835 3 9 - 15.6220 9 - 15.6220 9 10 - 9.34184 7 - 9.34184 7

. list school yhat yhat_fit if school<=10 & groups

17 Postestimación: valores ajustados (gráfico) Puedes trazar regresiones individuales, tipo twoway connected yhat_fit x1 if school<=10, connect(L)

-^2 0 -^1 0 0 10 20 Fitted values: xb

Zu

  • 40 - 20 20 40 0 Reading test

19 Useful links / Recommended books / References

  • DSS Online Training Section http://dss.princeton.edu/training/
  • UCLA Resources http://www.ats.ucla.edu/stat/
  • Princeton DSS Libguides http://libguides.princeton.edu/dss Books/References
  • “Beyond “Fixed Versus Random Effects”:A framework for improving substantive and statistical analysis of panel, time-series cross-sectional, and multilevel data” / Brandom Bartels http://polmeth.wustl.edu/retrieve.php?id=
  • “Robust Standard Errors for Panel Regressions with Cross-Sectional Dependence” / Daniel Hoechle, http://fmwww.bc.edu/repec/bocode/x/xtscc_paper.pdf
  • An Introduction to Modern Econometrics Using Stata / Christopher F. Baum, Stata Press,2006.
  • Data analysis using regression and multilevel/hierarchical models / Andrew Gelman, JenniferHill. Cambridge ; New York : Cambridge University Press, 2007.
  • Data Analysis Using Stata / Ulrich Kohler, Frauke Kreuter, 2 nd^ ed., Stata Press, 2009.
  • Designing Social Inquiry: Scientific Inference in Qualitative Research / Gary King, Robert O. Keohane, Sidney Verba, Princeton University Press , 1994.
  • Econometric analysis / William H. Greene. 6th ed., Upper Saddle River, N.J. : Prentice Hall,2008.
  • Introduction to econometrics / James H. Stock, Mark W. Watson. 2nd ed., Boston: Pearson Addison Wesley, 2007.
  • Statistical Analysis: an interdisciplinary introduction to univariate & multivariate methods / Sam Kachigan, New York : Radius Press, c
  • Statistics with Stata (updated for version 9) / Lawrence Hamilton, Thomson Books/Cole, 2006
  • Unifying Political Methodology: University Press, 1989 The Likelihood Theory of Statistical Inference / Gary King,Cambridge