class: center, middle # Tema 6. Heteroscedasticidad ### EconometrÃa #### Licenciatura en EconomÃa #### Dr. Francisco J. Cabrera-Hernández Otoño 2024 ##### CIDE Santa Fe, Ciudad de México. --- ## Outline - **.blue[Inferencia Robusta a Heteroscedasticidad]** - Tests de Heteroscedasticidad. - Weighted Least Squares. - Feasible Least Squares. - Errores estándar en cluster. --- ## Recuerde: - Bajo MLR1 a MLR4 se puede estimar `\(\beta\)` insesgadamente. - Bajo MLR5: `\(var(u|x_1, x_2... x_k) = \sigma_2\)` - Bajo MLR6: existe normalidad en los residuos `\(\mu \tilde{} N(0,\sigma^2)\)` independientemente de `\(x_1, x_2, x_k\)` - Los F-test y t-test no son válidos bajo heteroscedasticidad y sin normalidad (si `\(n \to \infty\)` MLR6 no es necesario). - **Los valores crÃticos se obtienen bajo la hipóteisis nula y provienen de una normal estandarizada.** --- ## Heteroscedasticidad Pura e Impura **Heterocedasticidad Pura:** - Ocurre cuando se viola MLR5 *y se cumple MLR1-MLR4* (i.e. modelo bien especificado) **Heteroscedasticidad Impura:** - Se da por un error de especificación (e.g. sesgo por omisión). - Por ejemplo, piense en la relación entre ingreso y educación cuando no se controla por industria de trabajo. - "The portion of the omitted effect *not represented by one of the included explanatory variables* must be absorbed by the error term". --- ## Consecuencias de la heteroscedasticidad - OLS es aun insesgado y consistente bajo heteroscedasticidad. - `\(R^2\)` y su interpretación no cambia: `$$R^2 = 1 - \frac {\sigma^2_\mu} {\sigma^2_y}$$` - en `\(R^2\)` Se usa `\(\sigma^2_\mu\)`, que es la varianza del error incondicional a `\(x_j\)`. No es afectada por heteroscedasticidad. `$$SSR/n \to \sigma^2_\mu; SST/n \to \sigma^2_y$$` - Sólo la varianza condicional `\(var(u|x_1, x_2... x_k) = \sigma_2\)` es afectada por heteroscedasticidad. --- ## Consecuencias de la heteroscedasticidad - No obstante la heteroscedasticidad afecta cálculo de `\(var(\hat\beta_1)\)` - Como se mencionó F-test y t-test no son válidos si se viola MLR5. - Sin MLR5 OLS ya no es **BLUE**. No es el más eficiente. - OLS ya no es asintóticamente eficiente. --- ## Consecuencias de la heteroscedasticidad Recuerde que con `\(n \to \infty\)` y bajo MLR5: `$$var(\hat \beta_1) = \frac {\hat\sigma^2} {\sum_{i=1}^n (x_i - \bar x)^2}$$` - `\(\hat{var}(\hat\beta_1)\)` se reduce a la tasa 1/n - La tasa a la que `\(\hat\beta_1\)` converge a `\(\beta_1\)` se refiere a la **eficiencia del estimador** Sin MLR5 y condicional en `\(x_i\)`: `$$var(\hat \beta_1) = \frac {{\sum_{i=1}^n (x_i - \bar x)^2} \hat\sigma_i^2} {[\sum_{i=1}^n (x_i - \bar x)^2]^2}$$` --- ##Velocidad de convergencia homoscedástica ``` r repet <- 5000 running_se <- NULL # Set seed for reproducibility set.seed(123456) # Simulate beta estimates and calculate the running mean for (i in 50:repet) { x <- rnorm(i) # Regressor x u <- rnorm(i, sd = 2) # Random error with some variance y <- 2 + beta_1_true * x + u # Define y, with beta_1 = 2 model <- lm(y ~ x) # Store beta_1 estimate # Calculate the running variance up to the current iteration robust_vcov <- vcovHC(model, type = "HC1") running_variances[i] <- diag(robust_vcov) } # we then plot the running variance... ``` --- ##Velocidad de convergencia homoscedástica <img src="data:image/png;base64,#hetero_files/figure-html/unnamed-chunk-2-1.png" width="65%" style="display: block; margin: auto;" /> --- ##Velocidad de convergencia heteroscedástica ``` r repet <- 5000 running_variances <- NULL # Set seed for reproducibility set.seed(123456) # Simulate beta estimates and calculate the running mean for (i in 50:repet) { x <- rnorm(i) # Regressor x u <- rnorm(i, sd = 2 + abs(x)) # Random error with some variance y <- 2 + beta_1_true * x + u # Define y, with beta_1 = 2 model <- lm(y ~ x) # Store beta_1 estimate # Calculate the running variance up to the current iteration robust_vcov <- vcovHC(model, type = "HC1") running_variances[i] <- diag(robust_vcov) } # we then plot the robust se estimates... ``` --- ##Velocidad de convergencia varianza de `\(\beta_1\)` <img src="data:image/png;base64,#hetero_files/figure-html/unnamed-chunk-4-1.png" width="75%" style="display: block; margin: auto;" /> --- ## SE Robustos a Heteroscedasticidad - With small sample sizes, the robust t-statistics can have distributions not very close to the t-distribution. - The robust standard errors and robust t statistics are justified only as the sample size becomes large - One reason the usual standard errors are still used in cross-sectional work is that under MLR5 and MLR6, the usual t statistics have exact t distributions. - The heteroskedasticity-robust version of F-Test has no simple form, but it can be computed using certain statistical packages. --- ##Derivación `\(\hat{var}(\hat\beta_1)\)` `$$\hat\beta_1= \frac{\sum_{i=1}^n (x_i-\bar x)(y_i-\bar y)}{\sum_{i=1}^n (x_i-\bar x)^2}$$` `$$\hat\beta_1= \frac{\sum_{i=1}^n (x_i-\bar x)y_i}{\sum_{i=1}^n (x_i-\bar x)^2}$$` `$$\hat\beta_1= \frac{\sum_{i=1}^n (x_i-\bar x)(\beta_0+\beta_1x_1+\mu_i)}{\sum_{i=1}^n (x_i-\bar x)^2}$$` `$$\hat\beta_1= \frac{\beta_1\sum_{i=1}^n (x_i-\bar x)x_i+ \sum_{i=1}^n (x_i-\bar x)\mu_i}{\sum_{i=1}^n (x_i-\bar x)^2}$$` `$$var(\hat\beta_1)= var \left( \beta_1 + \frac{\sum_{i=1}^n (x_i-\bar x)\mu_i}{\sum_{i=1}^n (x_i-\bar x)^2} \right)$$` --- ##Derivación `\(\hat{var}(\hat\beta_1)\)` `$$var(\hat\beta_1)= \frac{var\sum_{i=1}^n (x_i-\bar x)\mu_i}{[\sum_{i=1}^n (x_i-\bar x)^2]^2}$$` Con independencia de errores... `$$var(\hat\beta_1)= \frac{\sum_{i=1}^n var(x_i-\bar x)\mu_i}{[\sum_{i=1}^n (x_i-\bar x)^2]^2}$$` Under heteroskedasticity... `$$var(\hat\beta_1)= \frac{\sum_{i=1}^n (x_i-\bar x)^2var(\mu_i)}{[\sum_{i=1}^n (x_i-\bar x)^2]^2}$$` `$$\hat{var}(\hat\beta_1)= \frac{\sum_{i=1}^n (x_i-\bar x)^2 \hat\mu_i^2}{[\sum_{i=1}^n (x_i-\bar x)^2]^2}$$` --- ## Derivación `\(\hat{var}(\hat\beta_1)\)` `$$\hat{var}(\hat\beta_1)= \frac{\sum_{i=1}^n (x_i-\bar x)^2 \hat\mu_i^2}{[\sum_{i=1}^n (x_i-\bar x)^2]^2}$$` - En términos matriciales: `$$A\hat{var}(\hat\beta_1) = (XX)^{-1} \left(\sum_{i=1}^n\hat\mu_i^2 x_i'x_i \right)(XX)^{-1}$$` - Este es el "sandwich" estimator (White, HCO) --- ## SE Robustos a Heteroscedasticidad - White (1980) demostró que un estimador válido de `\(var(\hat\beta_1)\)`, para heteroscedasticidad de cualquier forma, incluida homoscedasticidad, es: `$$var(\hat \beta_1) = \frac {{\sum_{i=1}^n (x_i - \bar x)^2} \hat\sigma_i^2} {[\sum_{i=1}^n (x_i - \bar x)^2]^2} \to \hat{var}(\hat \beta_1) = \frac {{\sum_{i=1}^n (x_i - \bar x)^2} \hat\mu_i^2} {SST^2_x}$$` - Que se obtiene de los datos luego de la regresión OLS. `\(n . \hat{var}(\hat\beta_1)\)` converge en probabilidad a `\(E[x_i-\mu_x]^2\mu_i^2/(\sigma_x^2)^2\)` o `\(n . var(\hat\beta_1)\)` --- ## White SE matricial `\(y \tilde{} N(\mu, \sigma^2) \to \mu = X\beta \to y \tilde{} N(X\beta, \Sigma)\)`, donde `\(\Sigma=\sigma^2I\)` `\(Y: n\times1\)`; `\(X: n\times k\)`; `\(\beta: k\times 1\)`; `\(\Sigma:n \times n\)` - Matriz de varianza covarianza (sin supuestos) `$$\Sigma = \begin{pmatrix} \sigma_{11}^2 & \sigma_{12} & \sigma_{13} & \cdots & \sigma_{1n} \\ \sigma_{21} & \sigma_{22}^2 & \sigma_{23} & \cdots & \sigma_{2n} \\ \sigma_{31} & \sigma_{32} & \sigma_{33}^2 & \cdots & \sigma_{3n} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ \sigma_{n1} & \sigma_{n2} & \sigma_{n3} & \cdots & \sigma_{nn}^2 \end{pmatrix}$$` --- ## White SE matricial - Asumiendo independencia: `$$\Sigma = \begin{pmatrix} \sigma_{1}^2 & 0 & 0 & \cdots & 0 \\ 0 & \sigma_{2}^2 & 0 & \cdots & 0 \\ 0 & 0 & \sigma_{3}^2 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \cdots & \sigma_{n}^2 \end{pmatrix}$$` - Asumiendo homoscedasticidad: `$$\Sigma = \begin{pmatrix} \sigma_{}^2 & 0 & 0 & \cdots & 0 \\ 0 & \sigma_{}^2 & 0 & \cdots & 0 \\ 0 & 0 & \sigma_{}^2 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \cdots & \sigma_{}^2 \end{pmatrix} = \sigma^2 \begin{pmatrix} 1_{} & 0 & 0 & \cdots & 0 \\ 0 & 1_{} & 0 & \cdots & 0 \\ 0 & 0 & 1_{} & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \cdots & 1_{} \end{pmatrix}$$` --- ## White SE matricial `$$\hat\beta = (X'X)^{-1}X'y$$` `$$var(\hat\beta) = var[(X'X)^{-1}X'y]$$` - Esto es un `\(aX= a^2.var(X)\)`: `$$var(\hat\beta) = [(X'X)^{-1}X']\sigma^2 I [(X'X)^{-1}X']'$$` `$$var(\hat\beta) = \sigma^2[(X'X)^{-1}X'] I [X[(X'X)^{-1}]']$$` - Dado: `\([(X'X)^{-1}]'= (X'X)^{-1}\)` Bajo homoscedasticidad e independenicia de errores: `$$var(\hat\beta) = \sigma^2(X'X)^{-1}$$` --- ## White SE matricial Bajo Heteroscedasticidad: `$$var(\hat\beta) = [(X'X)^{-1}X']\Sigma[X(X'X)^{-1}]$$` - `\(\Sigma: n \times n\)` y no se pueden estimar `\(n \times n\)` elementos con n observaciones. - En lugar de estimar la matriz de varianza-covarianza se aproxima la diagonal con los residuos. Una versión "weighted". `$$var(\hat\beta) = (X'X)^{-1}(\sum_{i=1}^n\hat\mu_i^2x_i'x_i)(X'X)^{-1}$$` --- ## SE robusto para `\(\beta_j\)`: Los errores White, Huber, Eicker (HC1): `$$\hat{var}(\hat\beta_j)= \frac{\sum_{i=1}^n \hat{r}_{ij}^2 \hat\mu_i^2}{SSR_j^2}$$` - `\(\hat{r}_{ij}^2\)`: el efecto de `\(x_j\)` en `\(Y\)` luego del partialling out de `\(x_i\)` - Se pesa por varianza especÃfica de `\(X_j\)` respecto a `\(Y\)` - Se puede sustituir `\(SSR_j^2\)` por `\(SST_j(1-R^2)\)` para considerar multicolinearidad. --- ## Ejemplo: SE Robustos a Heteroscedasticidad <div class="figure" style="text-align: center"> <img src="data:image/png;base64,#SErob.png" alt=" " width="100%" /> <p class="caption"> </p> </div> - Idealmente se deberÃan de estimar y mostrar ambos errores (bajo MLR5 y HC1). Aunque nadie lo hace. - Si existen diferencias importantes, se tienen problemas de heteroscedastidicad y/o de tamaño de muestra. --- ## Outline - Inferencia Robusta a Heteroscedasticidad - **.blue[Tests de Heteroscedasticidad.]** - Weighted Least Squares. - Feasible Least Squares. - Errores estándar en cluster. --- ## Tests de heteroscedasticidad --- <style> .centered-word { position: absolute; top: 50%; left: 35%; transform: translate(-50%, -50%); } </style> <div class="centered-word"> <h3>.black[¿Dudas?]</h3> <h3>.black[francisco.cabrera@cide.edu]</h3> </div> <div class="figure" style="text-align: right"> <img src="data:image/png;base64,#bullseye.png" alt=" " width="45%" /> <p class="caption"> </p> </div>