Problema Aplicación 5.2

La función de costo generalizada Cobb-Douglas examinada en la aplicación 2 en el capítulo 4 es un caso especial de la función de costo translog (Transcendental Logarithmic)

\[\begin{align} \ln(C)=\alpha & + \beta\ln(Q) + \delta_k\ln(P_k) + \delta_l\ln(P_l) + \delta_f\ln(P_f)\\ & + \phi_{kk}\left[\frac{1}{2}\left(\ln(P_k)^2\right)\right] + \phi_{ll}\left[\frac{1}{2}\left(\ln(P_l)^2\right)\right] + \phi_{ff}\left[\frac{1}{2}\left(\ln(P_f)^2\right)\right]\\ & + \phi_{kl}\left[\ln(P_k)\right]\left[\ln(P_l)\right] + \phi_{kf}\left[\ln(P_k)\right]\left[\ln(P_f)\right] + \phi_{lf}\left[\ln(P_l)\right]\left[\ln(P_f)\right]\\ & + \gamma\left[\frac{1}{2}\left(\ln(Q)^2\right)\right]\\ & + \theta_{Qk}\left[\ln(Q)\right]\left[\ln(P_k)\right] + \theta_{Ql}\left[\ln(Q)\right]\left[\ln(P_l)\right] + \theta_{Qf}\left[\ln(Q)\right]\left[\ln(P_f)\right] + \epsilon \end{align}\]

Los requerimientos teóricos para la homogeneidad lineal en el factor de precios impone las siguientes restricciones:

\[\begin{align} \delta_k + \delta_l +\delta_f = 1 & &\phi_{kk} +\phi_{kl}+\phi_{kf}=0&&\phi_{kl} +\phi_{ll}+\phi_{lf}=0\\ \phi_{kf} +\phi_{lf}+\phi_{ff}=0&&\theta_{Qk}+\theta_{Ql}+\theta_{Qf}=0&& \end{align}\] Note que aunque la teoría subyacente requiere esto, el modelo puede ser estimado (mediante mínimos cuadrados) sin necesidad de imponer las restricciones de homogeneidad lineal. (Así se podría “probar” la teoría subyacente mediante pruebas de validación de estas restricciones. Ver Chistensen, Jorgenson, and Lau (1975)) se repetirá este ejercicio en el inciso b.

Un número de restricciones adicionales fueron exploradas en el estudio de Christensen y Greene (1976). Las hipótesis de homotecia de la estructura de producción agregarían las restricciones adicionales

\[\begin{align} \theta_{Qk}=0&&\theta_{Ql}=0&&\theta_{Qf}=0 \end{align}\]

La homogeneidad de la estructura de producción agrega la restricción \(\gamma=0\). La hipótesis de que todas las elasticidades de sustitución en la estructura de producción son iguales a \(-1\) es impuesta por las seis restricciones \(\phi_{ij}=0\) para toda \(i\) y \(j\).

Utilizaremos los datos de la aplicación anterior (Aplicación 4.2) para probar las restricciones. Para propósitos de este ejercicio denote mediante \(\beta_1,\dots,\beta_{15}\) a los \(15\) parámetros en la función de costo en el orden que aparecen en el modelo, comience en la primer linea moviéndose de izquierda a derecha y hacia abajo.

  1. Escriba la matriz \(R\) y el vector \(q\) de la ecuación (5-8) que serán necesarios para imponer las restricciones de homogeneidad lineal en precios

  2. “Pruebe” la teoría de producción utilizando todas las 158 observaciones. Use una prueba F para verificar las restricciones de la homogeneidad lineal. Note que puede usar la forma general del estadístico F de la ecuación (5-16) para llevar acabo la prueba. Christensen y Greene reforzaron las restricciones de homogeneidad lineal mediante la construcción de ellas en el modelo. Puede hacer esto dividiendo el costo, los precios de capital y trabajo por el precio del combustible. Los términos con el subindice \(f\) en el modelo pueden omitirse, dejando la ecuación con \(10\) parámetros. Compare las sumas de los cuadrados de los modelos para llevar acabo la prueba. Es claro que la prueba puede llevarse a cabo de cualquier manera y producirá el mismo resultado.

  3. Prueba la hipótesis de homotecia de la estructura de producción bajo las suposiciones de homogeneidad lineal en precios

  4. Pruebe la hipótesis de la función de costo generalizada Cobb-Douglas contra el modelo más general translog sugerido aquí, una vez más (y en adelante) asuma homogeneidad lineal en precios

  5. La función simple de Cobb-Douglas aparece en la primer linea del modelo. Pruebe la hipótesis del modelo de Cobb-Douglas contra la alternativa del modelo completo translog

  6. Pruebe la hipótesis del modelo generalizado de Cobb-Douglas contra el modelo homotetico translog

  7. ¿Cuál de las diferentes formas funcionales sugeridas aquí concluye que es la más apropiada para estos datos?

Solución

De acuerdo de al apéndice F de Greene edición 7.


Los datos de la edición 7 se pueden descargar en la siguiente página, de donde obtenemos la siguiente descripción


Leemos los datos directamente de la página

datos <- read.csv(url("http://pages.stern.nyu.edu/~wgreene/Text/Edition7/TableF4-4.csv"))
str(datos) 
## 'data.frame':    158 obs. of  10 variables:
##  $ id  : int  1 4 5 14 15 16 17 20 22 25 ...
##  $ YEAR: int  1970 1970 1970 1970 1970 1970 1970 1970 1970 1970 ...
##  $ COST: num  0.213 3.043 9.406 0.761 2.259 ...
##  $ Q   : num  8 869 1412 65 295 ...
##  $ PL  : num  6869 8373 7961 8972 8218 ...
##  $ SL  : num  0.3291 0.103 0.0891 0.2802 0.1772 ...
##  $ PK  : num  64.9 68.2 40.7 41.2 71.9 ...
##  $ SK  : num  0.42 0.291 0.157 0.128 0.162 ...
##  $ PF  : num  18 21.1 41.5 28.5 39.2 ...
##  $ SF  : num  0.251 0.606 0.754 0.592 0.661 ...
head(datos)
##   id YEAR   COST    Q      PL     SL     PK     SK     PF     SF
## 1  1 1970 0.2130    8 6869.47 0.3291 64.945 0.4197 18.000 0.2512
## 2  4 1970 3.0427  869 8372.96 0.1030 68.227 0.2913 21.067 0.6057
## 3  5 1970 9.4059 1412 7960.90 0.0891 40.692 0.1567 41.530 0.7542
## 4 14 1970 0.7606   65 8971.89 0.2802 41.243 0.1282 28.539 0.5916
## 5 15 1970 2.2587  295 8218.40 0.1772 71.940 0.1623 39.200 0.6606
## 6 16 1970 1.3422  183 5063.49 0.0960 74.430 0.2629 35.510 0.6411
tail(datos)
##      id YEAR    COST       Q       PL     SL     PK     SK     PF     SF
## 153 213 1970 22.1998  4800.0 12742.47 0.1239 33.840 0.1678 32.250 0.7083
## 154 214 1970  6.8293   946.6 10642.16 0.0883 43.600 0.1914 51.463 0.7203
## 155 215 1970  3.7605   377.0  7432.24 0.2117 74.120 0.2274 33.436 0.5609
## 156 216 1970  3.9822   391.0  5826.04 0.1926 78.288 0.0924 44.633 0.7151
## 157 217 1970 30.1880  5317.0  9586.63 0.0845 78.008 0.2009 41.840 0.7147
## 158 218 1970 67.8562 15220.0  6986.09 0.1451 74.025 0.2596 25.662 0.5945

Solución a)

R <- matrix( 0, nrow = 5, ncol = 15)
R[1, 3:5] <- 1
R[2, c(6, 9, 10)] <- 1
R[3, c(7, 9, 11)] <- 1
R[4, c(8, 10, 11)] <- 1
R[5, 13:15] <- 1

q <- matrix (c(1, 0, 0, 0, 0))

R
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
## [1,]    0    0    1    1    1    0    0    0    0     0     0     0     0     0
## [2,]    0    0    0    0    0    1    0    0    1     1     0     0     0     0
## [3,]    0    0    0    0    0    0    1    0    1     0     1     0     0     0
## [4,]    0    0    0    0    0    0    0    1    0     1     1     0     0     0
## [5,]    0    0    0    0    0    0    0    0    0     0     0     0     1     1
##      [,15]
## [1,]     0
## [2,]     0
## [3,]     0
## [4,]     0
## [5,]     1
q
##      [,1]
## [1,]    1
## [2,]    0
## [3,]    0
## [4,]    0
## [5,]    0

Solución b)

str(datos)
## 'data.frame':    158 obs. of  10 variables:
##  $ id  : int  1 4 5 14 15 16 17 20 22 25 ...
##  $ YEAR: int  1970 1970 1970 1970 1970 1970 1970 1970 1970 1970 ...
##  $ COST: num  0.213 3.043 9.406 0.761 2.259 ...
##  $ Q   : num  8 869 1412 65 295 ...
##  $ PL  : num  6869 8373 7961 8972 8218 ...
##  $ SL  : num  0.3291 0.103 0.0891 0.2802 0.1772 ...
##  $ PK  : num  64.9 68.2 40.7 41.2 71.9 ...
##  $ SK  : num  0.42 0.291 0.157 0.128 0.162 ...
##  $ PF  : num  18 21.1 41.5 28.5 39.2 ...
##  $ SF  : num  0.251 0.606 0.754 0.592 0.661 ...
regresion_Res_b <- lm (log(COST/PF) ~ log(Q) + log(PK/PF) + log(PL/PF)
                  + I(log(PL/PF)**2/2) + I(log(PK/PF)**2/2) 
                  + I(log(PK/PF)*log(PL/PF)) + I(log(Q)**2/2) 
                  + I(log(Q)*log(PK/PF)) +I(log(Q)*log(PL/PF)), 
                  data = datos)
#summary(regresion_Res_b)
s1 <- summary(regresion_Res_b)
ee0 <- sum(s1$residuals**2)

regresion_Com_b <- lm (log(COST) ~ log(Q) + log(PK) + log(PL) + log(PF)
                  + I(log(PK)**2/2) + I(log(PL)**2/2) + I(log(PF)**2/2)   
                  + log(PK):log(PL) + log(PK):log(PF) + log(PL):log(PF)
                  + I(log(Q)**2/2) + log(Q):log(PK) + log(Q):log(PL)
                  + log(Q):log(PF) , 
                  data = datos)
#summary(regresion_Com_b)
s2 <- summary(regresion_Com_b)
ee1 <- sum(s2$residuals**2)

Fstat15= ((ee0 - ee1)/5)/(ee1/(158-15))
Fstat15
## [1] 4.323089
qf(0.05, 5, 143, lower.tail=F)
## [1] 2.27749
coef(regresion_Com_b)
##     (Intercept)          log(Q)         log(PK)         log(PL)         log(PF) 
##    -76.25926149     -1.08042535      6.38079702     14.71829256     -0.89473291 
##  I(log(PK)^2/2)  I(log(PL)^2/2)  I(log(PF)^2/2)   I(log(Q)^2/2) log(PK):log(PL) 
##     -0.32741427     -1.53852735     -0.07350556      0.05297849     -0.57205049 
## log(PK):log(PF) log(PL):log(PF)  log(Q):log(PK)  log(Q):log(PL)  log(Q):log(PF) 
##     -0.02402470      0.16228289      0.04014440      0.13104059      0.05865220
R <- matrix( 0, nrow = 5, ncol = 15)
R[1, 3:5] <- 1
R[2, c(11, 12, 8)] <- 1
R[3, c(6, 10, 11)] <- 1
R[4, 13:15] <- 1
R[5, c(10, 7, 12)] <- 1

car::linearHypothesis(regresion_Com_b, R,q)
## Linear hypothesis test
## 
## Hypothesis:
## log(PK)  + log(PL)  + log(PF) = 1
## I(log(PF)^2/2)  + log(PK):log(PF)  + log(PL):log(PF) = 0
## I(log(PK)^2/2)  + log(PK):log(PL)  + log(PK):log(PF) = 0
## log(Q):log(PK)  + log(Q):log(PL)  + log(Q):log(PF) = 0
## I(log(PL)^2/2)  + log(PK):log(PL)  + log(PL):log(PF) = 0
## 
## Model 1: restricted model
## Model 2: log(COST) ~ log(Q) + log(PK) + log(PL) + log(PF) + I(log(PK)^2/2) + 
##     I(log(PL)^2/2) + I(log(PF)^2/2) + log(PK):log(PL) + log(PK):log(PF) + 
##     log(PL):log(PF) + I(log(Q)^2/2) + log(Q):log(PK) + log(Q):log(PL) + 
##     log(Q):log(PF)
## 
##   Res.Df    RSS Df Sum of Sq      F  Pr(>F)   
## 1    148 2.8369                               
## 2    143 2.4644  5    0.3725 4.3231 0.00108 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Concluimos que se rechaza la hipótesis nula a favor de la alternativa lo cual indica que la función no presenta condiciones de homogeneidad en precios.

Solución c)

R1 <- matrix( 0, nrow = 7, ncol = 15)
R1[1, 3:5] <- 1
R1[2, c(11, 12, 8)] <- 1
R1[3, c(6, 10, 11)] <- 1
R1[4, c(10, 7, 12)] <- 1
R1[5, c(13)] <- 1
R1[6, c(14)] <- 1
R1[7, c(15)] <- 1
R1
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
## [1,]    0    0    1    1    1    0    0    0    0     0     0     0     0     0
## [2,]    0    0    0    0    0    0    0    1    0     0     1     1     0     0
## [3,]    0    0    0    0    0    1    0    0    0     1     1     0     0     0
## [4,]    0    0    0    0    0    0    1    0    0     1     0     1     0     0
## [5,]    0    0    0    0    0    0    0    0    0     0     0     0     1     0
## [6,]    0    0    0    0    0    0    0    0    0     0     0     0     0     1
## [7,]    0    0    0    0    0    0    0    0    0     0     0     0     0     0
##      [,15]
## [1,]     0
## [2,]     0
## [3,]     0
## [4,]     0
## [5,]     0
## [6,]     0
## [7,]     1
q1 <- matrix (c(1, 0, 0, 0, 0, 0, 0))

car::linearHypothesis(regresion_Com_b, R1,q1)
## Linear hypothesis test
## 
## Hypothesis:
## log(PK)  + log(PL)  + log(PF) = 1
## I(log(PF)^2/2)  + log(PK):log(PF)  + log(PL):log(PF) = 0
## I(log(PK)^2/2)  + log(PK):log(PL)  + log(PK):log(PF) = 0
## I(log(PL)^2/2)  + log(PK):log(PL)  + log(PL):log(PF) = 0
## log(Q):log(PK) = 0
## log(Q):log(PL) = 0
## log(Q):log(PF) = 0
## 
## Model 1: restricted model
## Model 2: log(COST) ~ log(Q) + log(PK) + log(PL) + log(PF) + I(log(PK)^2/2) + 
##     I(log(PL)^2/2) + I(log(PF)^2/2) + log(PK):log(PL) + log(PK):log(PF) + 
##     log(PL):log(PF) + I(log(Q)^2/2) + log(Q):log(PK) + log(Q):log(PL) + 
##     log(Q):log(PF)
## 
##   Res.Df    RSS Df Sum of Sq      F   Pr(>F)   
## 1    150 2.8906                                
## 2    143 2.4644  7   0.42627 3.5336 0.001569 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Se rechaza la hipótesis nula debido al p valor y el estadístico F “alto” por lo tanto rechazamos que se tenga la propiedad de homogeneidad y homotecia.

Solución d)

La función generalizada de Cobb-Douglas tiene la siguiente estructura

\[\begin{align} \ln(C)=\alpha & + \beta\ln(Q) + \gamma\left[\frac{1}{2}\left(\ln(Q)^2\right)\right]+\delta_k\ln(P_k) + \delta_l\ln(P_l) + \delta_f\ln(P_f)+ \epsilon \end{align}\] la homogeneidad lineal junto con las demás variables iguales a cero generan

\[\begin{align} \beta_3 + \beta_4 +\beta_5 = 1 & & \beta_i\neq0,\;i=1,2,9&& \end{align}\]

R2 <- matrix( 0, nrow = 10, ncol = 15)
R2[1, 3:5] <- 1
R2[2, 6] <- 1
R2[3, 7] <- 1
R2[4, 8] <- 1
R2[5, 10] <- 1
R2[6, 11] <- 1
R2[7, 12] <- 1
R2[8, 13] <- 1
R2[9, 14] <- 1
R2[10, 15] <- 1
R2
##       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
##  [1,]    0    0    1    1    1    0    0    0    0     0     0     0     0
##  [2,]    0    0    0    0    0    1    0    0    0     0     0     0     0
##  [3,]    0    0    0    0    0    0    1    0    0     0     0     0     0
##  [4,]    0    0    0    0    0    0    0    1    0     0     0     0     0
##  [5,]    0    0    0    0    0    0    0    0    0     1     0     0     0
##  [6,]    0    0    0    0    0    0    0    0    0     0     1     0     0
##  [7,]    0    0    0    0    0    0    0    0    0     0     0     1     0
##  [8,]    0    0    0    0    0    0    0    0    0     0     0     0     1
##  [9,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [10,]    0    0    0    0    0    0    0    0    0     0     0     0     0
##       [,14] [,15]
##  [1,]     0     0
##  [2,]     0     0
##  [3,]     0     0
##  [4,]     0     0
##  [5,]     0     0
##  [6,]     0     0
##  [7,]     0     0
##  [8,]     0     0
##  [9,]     1     0
## [10,]     0     1
q2 <- matrix (c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0))

car::linearHypothesis(regresion_Com_b, R2,q2)
## Linear hypothesis test
## 
## Hypothesis:
## log(PK)  + log(PL)  + log(PF) = 1
## I(log(PK)^2/2) = 0
## I(log(PL)^2/2) = 0
## I(log(PF)^2/2) = 0
## log(PK):log(PL) = 0
## log(PK):log(PF) = 0
## log(PL):log(PF) = 0
## log(Q):log(PK) = 0
## log(Q):log(PL) = 0
## log(Q):log(PF) = 0
## 
## Model 1: restricted model
## Model 2: log(COST) ~ log(Q) + log(PK) + log(PL) + log(PF) + I(log(PK)^2/2) + 
##     I(log(PL)^2/2) + I(log(PF)^2/2) + log(PK):log(PL) + log(PK):log(PF) + 
##     log(PL):log(PF) + I(log(Q)^2/2) + log(Q):log(PK) + log(Q):log(PL) + 
##     log(Q):log(PF)
## 
##   Res.Df    RSS Df Sum of Sq      F   Pr(>F)   
## 1    153 2.9049                                
## 2    143 2.4644 10   0.44055 2.5564 0.007178 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Rechazamos nuevamente la hipótesis nula, por lo cual no podríamos ajustar una Cobb-Douglas generalizada con homogeneidad en precios

Solución e)

A lo anterior agregamos la hipótesis \[\beta_2=0\]

R3 <- matrix( 0, nrow = 11, ncol = 15)
R3[1, 3:5] <- 1
R3[2, 6] <- 1
R3[3, 7] <- 1
R3[4, 8] <- 1
R3[5, 10] <- 1
R3[6, 11] <- 1
R3[7, 12] <- 1
R3[8, 13] <- 1
R3[9, 14] <- 1
R3[10, 15] <- 1
R3[11, 9] <- 1

R3
##       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
##  [1,]    0    0    1    1    1    0    0    0    0     0     0     0     0
##  [2,]    0    0    0    0    0    1    0    0    0     0     0     0     0
##  [3,]    0    0    0    0    0    0    1    0    0     0     0     0     0
##  [4,]    0    0    0    0    0    0    0    1    0     0     0     0     0
##  [5,]    0    0    0    0    0    0    0    0    0     1     0     0     0
##  [6,]    0    0    0    0    0    0    0    0    0     0     1     0     0
##  [7,]    0    0    0    0    0    0    0    0    0     0     0     1     0
##  [8,]    0    0    0    0    0    0    0    0    0     0     0     0     1
##  [9,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [10,]    0    0    0    0    0    0    0    0    0     0     0     0     0
## [11,]    0    0    0    0    0    0    0    0    1     0     0     0     0
##       [,14] [,15]
##  [1,]     0     0
##  [2,]     0     0
##  [3,]     0     0
##  [4,]     0     0
##  [5,]     0     0
##  [6,]     0     0
##  [7,]     0     0
##  [8,]     0     0
##  [9,]     1     0
## [10,]     0     1
## [11,]     0     0
q3 <- matrix (c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))

car::linearHypothesis(regresion_Com_b, R3,q3)
## Linear hypothesis test
## 
## Hypothesis:
## log(PK)  + log(PL)  + log(PF) = 1
## I(log(PK)^2/2) = 0
## I(log(PL)^2/2) = 0
## I(log(PF)^2/2) = 0
## log(PK):log(PL) = 0
## log(PK):log(PF) = 0
## log(PL):log(PF) = 0
## log(Q):log(PK) = 0
## log(Q):log(PL) = 0
## log(Q):log(PF) = 0
## I(log(Q)^2/2) = 0
## 
## Model 1: restricted model
## Model 2: log(COST) ~ log(Q) + log(PK) + log(PL) + log(PF) + I(log(PK)^2/2) + 
##     I(log(PL)^2/2) + I(log(PF)^2/2) + log(PK):log(PL) + log(PK):log(PF) + 
##     log(PL):log(PF) + I(log(Q)^2/2) + log(Q):log(PK) + log(Q):log(PL) + 
##     log(Q):log(PF)
## 
##   Res.Df    RSS Df Sum of Sq      F    Pr(>F)    
## 1    154 6.6682                                  
## 2    143 2.4643 11    4.2039 22.176 < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Nuevamente rechazamos la hipótesis nula, así no podemos afirmar que la estructura es de una Cobb-Douglas sencilla.

Solución f)

regresion_Com_f <- lm (
              log(COST/PF) ~ log(Q) + log(PK/PF) + log(PL/PF)
             + I(log(PL/PF)**2/2) + I(log(PK/PF)**2/2) 
             + I(log(PK/PF)*log(PL/PF)) + I(log(Q)**2/2), 
             data = datos)
summary(regresion_Com_f)
## 
## Call:
## lm(formula = log(COST/PF) ~ log(Q) + log(PK/PF) + log(PL/PF) + 
##     I(log(PL/PF)^2/2) + I(log(PK/PF)^2/2) + I(log(PK/PF) * log(PL/PF)) + 
##     I(log(Q)^2/2), data = datos)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.41834 -0.09362 -0.00326  0.08699  0.39111 
## 
## Coefficients:
##                             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                -8.701982   3.094947  -2.812  0.00559 ** 
## log(Q)                      0.400994   0.032074  12.502  < 2e-16 ***
## log(PK/PF)                 -0.186436   0.753177  -0.248  0.80483    
## log(PL/PF)                  0.872461   1.163765   0.750  0.45462    
## I(log(PL/PF)^2/2)          -0.137281   0.218499  -0.628  0.53077    
## I(log(PK/PF)^2/2)          -0.090511   0.208993  -0.433  0.66558    
## I(log(PK/PF) * log(PL/PF))  0.073668   0.148147   0.497  0.61973    
## I(log(Q)^2/2)               0.061008   0.004408  13.840  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1388 on 150 degrees of freedom
## Multiple R-squared:  0.9923, Adjusted R-squared:  0.9919 
## F-statistic:  2747 on 7 and 150 DF,  p-value: < 2.2e-16
coef(regresion_Com_f)
##                (Intercept)                     log(Q) 
##                -8.70198236                 0.40099411 
##                 log(PK/PF)                 log(PL/PF) 
##                -0.18643650                 0.87246056 
##          I(log(PL/PF)^2/2)          I(log(PK/PF)^2/2) 
##                -0.13728118                -0.09051097 
## I(log(PK/PF) * log(PL/PF))              I(log(Q)^2/2) 
##                 0.07366783                 0.06100758
R4 <- matrix( 0, nrow = 3, ncol = 8)
R4[1, 5] <- 1
R4[2, 6] <- 1
R4[3, 7] <- 1
R4
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,]    0    0    0    0    1    0    0    0
## [2,]    0    0    0    0    0    1    0    0
## [3,]    0    0    0    0    0    0    1    0
q4 <- matrix (c(0, 0, 0))

car::linearHypothesis(regresion_Com_f, R4,q4)
## Linear hypothesis test
## 
## Hypothesis:
## I(log(PL/PF)^2/2) = 0
## I(log(PK/PF)^2/2) = 0
## I(log(PK/PF) * log(PL/PF)) = 0
## 
## Model 1: restricted model
## Model 2: log(COST/PF) ~ log(Q) + log(PK/PF) + log(PL/PF) + I(log(PL/PF)^2/2) + 
##     I(log(PK/PF)^2/2) + I(log(PK/PF) * log(PL/PF)) + I(log(Q)^2/2)
## 
##   Res.Df    RSS Df Sum of Sq      F Pr(>F)
## 1    153 2.9049                           
## 2    150 2.8906  3  0.014276 0.2469 0.8634

No podemos rechazar la hipótesis respecto a que asumir un translog homotético y homogéneo es posible ajustar los datos a un modelo generalizado homogéneo Cobb-Douglas

Solución g)

Asumiendo que los datos se ajustan a un translog general no podemos asumir ninguna de las simplificaciones indicadas. Sin embargo, asumiendo un translog homotético y homogéneo es posible ajustar los datos a un modelo generalizado homogéneo Cobb-Douglas

Tarea lunes 30 de marzo

Objetivos: Complementar nuestro conocimiento del modelo de regresión lineal múltiple con las distintas estrategias de selección de modelos.

Secciones: 5.8 a 5.10 (Greene)

Ejemplos y ejercicios: Réplica de los ejemplos 5.7 y 5.8 (en R). Ejercicio Aplicado 4.

Fecha de entrega: Lunes 30 de marzo.

Ejemplo 5.7

Prueba para una función de comsumo

Gaver y Geisel (1974) proonon dos formas de una función de consumo:

\[H_0:\,C_t = \beta_1 + \beta_2Y_t + \beta_3Y_{t-1} + \epsilon_{0t}\] y

\[H_1:\,C_t = \gamma_1 + \gamma_2Y_t + \gamma_3C_{t-1} + \epsilon_{1t}\] El primer modelo establece que el consumo responde a cambios en el ingreso en dos periodos, mientras que el segundo establece que los efectos del ingreso sobre el consumo persisten por varios periodos. Los datos trimestrales sobre el consumo real agregado de EE. UU. Y el ingreso real disponible se proporcionan en el Apéndice F5.2. Aquí aplicamos la prueba \(J\) para estos datos y las dos especificaciones propuestas. Primero los dos modelos son estimados de forma separada (usando observaciones de 1950.2 hasta 2000.4). La regresión de mínimos cuadrado de \(C\) sobre una constante, \(Y\), y un retraso \(Y\) y los valores estimados para el segundo modelo producen un estimado de \(\lambda=1.0145\) con una razón \(t=62.861\). Así, \(H_0\) debe rechazarse a favor de \(H_1\). Pero invirtiendo los roles de \(H_0\) y \(H_1\) obtenemos un estimado de \(\lambda=-10.677\) con un radio \(t=-7.188\). Así, \(H_1\) es rechazado también

Solución

De acuerdo de al apéndice F de Greene edición 7.



Los datos de la edición 7 se pueden descargar en la siguiente página, de donde obtenemos la siguiente descripción



Leemos los datos directamente de la página

datos <- read.csv(url("http://pages.stern.nyu.edu/~wgreene/Text/Edition7/TableF5-2.csv"))
str(datos) 
## 'data.frame':    204 obs. of  14 variables:
##  $ YEAR    : int  1950 1950 1950 1950 1951 1951 1951 1951 1952 1952 ...
##  $ QTR     : int  1 2 3 4 1 2 3 4 1 2 ...
##  $ REALGDP : num  1610 1659 1723 1754 1774 ...
##  $ REALCONS: num  1059 1076 1131 1098 1123 ...
##  $ REALINVS: num  198 220 240 272 243 ...
##  $ REALGOVT: num  361 366 360 382 422 ...
##  $ REALDPI : num  1186 1178 1196 1210 1208 ...
##  $ CPI_U   : num  70.6 71.4 73.2 74.9 77.3 77.6 78.2 79.3 78.8 79.4 ...
##  $ M1      : num  110 112 113 114 115 ...
##  $ TBILRATE: num  1.12 1.17 1.23 1.35 1.4 1.53 1.63 1.65 1.64 1.68 ...
##  $ UNEMP   : num  6.4 5.6 4.6 4.2 3.5 3.1 3.2 3.4 3.1 3 ...
##  $ POP     : num  149 150 151 152 152 ...
##  $ INFL    : num  0 4.51 9.96 9.18 12.62 ...
##  $ REALINT : num  0 -3.34 -8.73 -7.83 -11.22 ...
#head(datos)
#tail(datos)
library(dplyr)
library(lmtest)
datos <- mutate(datos, 
                clag1 = lag(REALCONS,k=-1),
                ylag1 = lag(REALDPI,k=-1))
fm1 <- lm(REALCONS ~ REALDPI + ylag1, data = datos)
fm2 <- lm(REALCONS ~ REALDPI + clag1, data = datos)
jtest(fm1,fm2)
## J test
## 
## Model 1: REALCONS ~ REALDPI + ylag1
## Model 2: REALCONS ~ REALDPI + clag1
##                 Estimate Std. Error t value  Pr(>|t|)    
## M1 + fitted(M2)   1.0145    0.01614 62.8605 < 2.2e-16 ***
## M2 + fitted(M1) -10.6766    1.48542 -7.1876 1.299e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Ejemplo 5.8

Solución

Primero investigamos el ejemplo 4.10 que tiene que ver con la siguiente estimación:

\[\ln(P) = -8.42653 +1.33374\ln(\text{Area})- 0.16537\,\text{razonDeAespecto} + e\]

Verificamos esta estimación:

datos <- read.csv(url("http://pages.stern.nyu.edu/~wgreene/Text/Edition7/TableF4-1.csv"))
str(datos) 
## 'data.frame':    430 obs. of  6 variables:
##  $ PRICE  : num  3.994 8.8 0.132 2.038 1.488 ...
##  $ HEIGHT : num  21.3 31.9 6.9 25.7 25.7 25.6 25.5 26 25.6 25.6 ...
##  $ WIDTH  : num  25.6 25.6 15.9 32 32 31.9 35.6 34.3 36.2 36.4 ...
##  $ SIGNED : int  1 1 0 1 1 1 1 1 1 1 ...
##  $ PICTURE: int  1 2 3 4 4 4 5 5 5 6 ...
##  $ HOUSE  : num  1 2 3 2 2 1 1 2 2 2 ...
regresion <- lm(log(PRICE) ~ I(log(HEIGHT*WIDTH)) + I(HEIGHT/WIDTH), data=datos)
summary(regresion)
## 
## Call:
## lm(formula = log(PRICE) ~ I(log(HEIGHT * WIDTH)) + I(HEIGHT/WIDTH), 
##     data = datos)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.4834 -0.6996 -0.0998  0.7330  2.9387 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            -8.42653    0.61183 -13.773   <2e-16 ***
## I(log(HEIGHT * WIDTH))  1.33372    0.09072  14.702   <2e-16 ***
## I(HEIGHT/WIDTH)        -0.16537    0.12753  -1.297    0.195    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.103 on 427 degrees of freedom
## Multiple R-squared:  0.3362, Adjusted R-squared:  0.3331 
## F-statistic: 108.1 on 2 and 427 DF,  p-value: < 2.2e-16
resettest(regresion)
## 
##  RESET test
## 
## data:  regresion
## RESET = 8.5127, df1 = 2, df2 = 425, p-value = 0.0002372

Ejercicio aplicado 4

La prueba \(J\) en el ejemplo 5.7 se realizo utilizando mas de 50 años de datos. Es optimista esperar que la estructura subyacente de la economía no cambie en 50 años. ¿la estructura de la prueba obtenida en el ejemplo 5.7 persiste si este se basa solo en los datos de 1980 al 2000? Repita el calculo con este subconjunto de datos.

Solución

Leemos los datos directamente de la página

datos <- read.csv(url("http://pages.stern.nyu.edu/~wgreene/Text/Edition7/TableF5-2.csv"))
str(datos) 
## 'data.frame':    204 obs. of  14 variables:
##  $ YEAR    : int  1950 1950 1950 1950 1951 1951 1951 1951 1952 1952 ...
##  $ QTR     : int  1 2 3 4 1 2 3 4 1 2 ...
##  $ REALGDP : num  1610 1659 1723 1754 1774 ...
##  $ REALCONS: num  1059 1076 1131 1098 1123 ...
##  $ REALINVS: num  198 220 240 272 243 ...
##  $ REALGOVT: num  361 366 360 382 422 ...
##  $ REALDPI : num  1186 1178 1196 1210 1208 ...
##  $ CPI_U   : num  70.6 71.4 73.2 74.9 77.3 77.6 78.2 79.3 78.8 79.4 ...
##  $ M1      : num  110 112 113 114 115 ...
##  $ TBILRATE: num  1.12 1.17 1.23 1.35 1.4 1.53 1.63 1.65 1.64 1.68 ...
##  $ UNEMP   : num  6.4 5.6 4.6 4.2 3.5 3.1 3.2 3.4 3.1 3 ...
##  $ POP     : num  149 150 151 152 152 ...
##  $ INFL    : num  0 4.51 9.96 9.18 12.62 ...
##  $ REALINT : num  0 -3.34 -8.73 -7.83 -11.22 ...
datossubset <- filter(datos, YEAR >= 1980)
#datossubset <- bind_rows(filter(datos,YEAR ==1980&QTR>=3),
#                         datossubset)
datossubset <- mutate(datossubset, 
                clag1 = lag(REALCONS,k=1),
                ylag1 = lag(REALDPI,k=1))

fm1 <- lm(REALCONS ~ REALDPI + ylag1, data = datossubset)
fm2 <- lm(REALCONS ~ REALDPI + clag1, data = datossubset)
jtest(fm1,fm2)
## J test
## 
## Model 1: REALCONS ~ REALDPI + ylag1
## Model 2: REALCONS ~ REALDPI + clag1
##                 Estimate Std. Error t value  Pr(>|t|)    
## M1 + fitted(M2)   1.0494    0.04671 22.4674 < 2.2e-16 ***
## M2 + fitted(M1)  -1.1347    0.31933 -3.5535  0.000645 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Valores de libro \(\alpha=1.03\) y \(23.27\), \(\alpha=-1.24\) y \(t=-3.062\) los cuales solo se pueden aproximar si se toman los datos desde partir del tercer cuarto de 1980, pero las conclusiones son las mismas, se tiene basícamentente el mismo resultado, son utilizar los datos de todos los años.

Tarea lunes 06 de abril

Objetivos: Analizar la regresión con variables binarias y profundizar en la aplicación del estimador de diferencias de diferencias.

Referencias: Capítulo 6 de Greene para binarias en general; Sección 6.5.2 de Wooldridge (negro) para DD; Sección 13.2 de Wooldridge (baby) para DD

Complementariamente, Capítulo 5 de “Mastering Metrics” y Capítulo 7 de “La Evaluación del Impacto en la Práctica”

Ejemplos y ejercicios:

  • Ejercicios cap 6 de Greene (teóricos y aplicados)
  • Ejercicios computacionales C1 y C2 del Capítulo 13 de Wooldridge (baby)
  • Ejercicios: 6.7, 6.11 de Wooldridge (Cross)
  • Buscar dos referencias en la literatura de la econometría aplicada que utilicen el método de diferencias de diferencias (differences in differences); leerlas y elaborar un breve resumen del uso del método (incluida cualquier crítica que los autores hagan al mismo)

Ejercicios Aplicados Greene

Ejercicio aplicado 1 captulo 6

n1 <- c("id", "education", "lwage", "pexper", "tt")
n2 <- c("abil", "mothed", "fathed", "brhome", "nsib")

datosvar <- read.csv(file.choose(),header = FALSE, sep = ",", col.names = n1) #Datos de time_var
datosinvar <- read.csv(file.choose(),header = FALSE, sep = ",", col.names = n2) #Datos de time_invar
cid <- as.data.frame(table(datosvar[,1]))
datosinvar2 <- transform(datosinvar ,  nid = cid[,2])
datosinvar3 <- as.data.frame(lapply(datosinvar2, rep, datosinvar2$nid)) 
datosinvar3 <- data.frame(datosinvar3[,1:5])
datos <- data.frame(datosvar, datosinvar3)
reg1 <- lm(lwage ~ education + abil + pexper + mothed + fathed + brhome + nsib, data = datos)
summary(reg1)
coef1 <- reg1$coefficients
md1 <- c(1, 12 , mean(datos$abil) , mean(datos$pexper) , mean(datos$mothed) ,
         mean(datos$fathed), 0 ,  mean(datos$nsib))
lw1 <- coef1%*%md1
mv1 <- coef1[2]*exp(lw1)
mv1
reg2 <- lm(lwage ~ education + abil + pexper + mothed + fathed + nsib, data = datos)
summary(reg2)
coef2 <- reg2$coefficients
md2 <- c(1, 12 , mean(datos$abil) , mean(datos$pexper) , mean(datos$mothed) ,
         mean(datos$fathed), mean(datos$nsib))
lw2 <- coef2%*%md2
mv2 <- exp(lw2)*coef2[2]
mv2
hist(datos$education)
datos <- transform(datos, HS = ifelse(datos$education <= 12,1,0))
datos <- transform(datos, COL = ifelse(datos$education > 12 & 
                                         datos$education <=16 ,1,0))
datos <- transform(datos, GRAD = ifelse(datos$education > 16 ,1,0))
reg3 <- lm(lwage ~ COL + GRAD + abil + pexper + mothed + fathed +
             brhome + nsib, data = datos)
summary(reg3)
coef3 <- reg3$coefficients
md31 <- c(1, 0, 1 , mean(datos$abil) , mean(datos$pexper) , mean(datos$mothed) ,
          mean(datos$fathed), 1 , mean(datos$nsib))
lw31 <- coef3%*%md31
mv31 <- exp(lw31)*coef3[3]
mv31
md30 <- c(1, 0 ,1 , mean(datos$abil) , mean(datos$pexper) , mean(datos$mothed) ,
          mean(datos$fathed), 0,  mean(datos$nsib))
lw30 <- coef3%*%md30
mv30 <- coef3[3]*exp(lw30)
mv30
EMT <- coef3[3]
EMT
datos <- transform(datos, education2 = education^2)
reg4 <- lm(lwage ~ education + education2 + abil + pexper + mothed + 
             fathed + brhome + nsib, data = datos)
summary(reg4)
coef4 <- reg4$coefficients
means <- c(1, 0 , 0 , mean(datos$abil) , mean(datos$pexper) ,
           mean(datos$mothed) , mean(datos$fathed), mean(datos$brhome) , mean(datos$nsib))
a <- means %*% coef4
fncedu <- function(educ){a + coef4[2]*educ + coef4[3]*educ^2}
plot(
  fncedu, 
  from = 1, 
  to   = 20,
  xlab = "A?os de educaci?n" , ylab = "Funci?n" ,
  col="blue"
)
datos <- transform(datos, EDUCABILITY = education * abil)
reg5 <- lm(lwage ~ education + abil + EDUCABILITY + pexper + mothed + fathed + brhome + nsib, data = datos)
summary(reg5)
coef5 <- reg5$coefficients
md51 <- c(1, mean(datos$education), mean(datos$abil) , mean(datos$EDUCABILITY), 
          mean(datos$pexper) , mean(datos$mothed) , mean(datos$fathed), 1 , mean(datos$nsib))
lw51 <- coef5%*%md51
mv51 <- (coef5[2] + (coef5[4]*md51[3]))*exp(lw51)
mv51
md50 <- c(1, mean(datos$education), mean(datos$abil) , mean(datos$EDUCABILITY), 
          mean(datos$pexper) , mean(datos$mothed) , mean(datos$fathed), 0 , mean(datos$nsib))
lw50 <- coef5%*%md51
mv50 <- (coef5[2] + (coef5[4]*md50[3]))*exp(lw50)
mv50
ma <- mean(datos$abil)
vm <- coef5[2] + coef5[4]*ma
names(vm) <- c("")
vm
MVC <- vcov(reg5)
sdvm <- sqrt(MVC[2,2]) + (ma^2)*MVC[4,4] + 2*ma*MVC[2,4]
low <- vm - 1.96*sdvm
up <- vm + 1.96*sdvm
interval <- c(low, up)
names(interval) <- c("lower","upper" )
interval
names(datos)
reg6 <- lm(lwage ~ education + education2 + abil + EDUCABILITY + pexper + 
             mothed + fathed + brhome + nsib, data = datos)
summary(reg6)
coef6 <- reg6$coefficients
lowab = ifelse(datos$abil < ma ,1,0)
sum(lowab) #Coincide con los datos del libro
higab <- 1 - lowab
sum(higab)
mlowab <- lowab%*%datos$abil / lowab%*%lowab
mlowab
mhigab <- higab%*%datos$abil / higab%*%higab
mhigab
means2 <- c(1, mean(datos$pexper) , mean(datos$mothed) , 
            mean(datos$fathed), mean(datos$brhome) , mean(datos$nsib))
names(coef6)
b1 <- c(coef6[1] , coef6[6] , coef6[7] , coef6[8] , coef6[9] , coef6[10])
a<- b1%*%means2

al <- a + coef6[4]*mlowab
ah <- a + coef6[4]*mhigab
f1 <- function(edu){al + coef6[2]*edu + coef6[3]*edu^2 + coef6[5]*mlowab*edu}
f2 <- function(edu){ah + coef6[2]*edu + coef6[3]*edu^2 + coef6[5]*mhigab*edu}

plot(
  f1, 
  from = 9, 
  to   = 21,
  xlab = "A?os de educaci?n" , ylab = "Funci?n" ,
  col="blue",
  ylim=c(2,2.8)
)
plot (f2, 
      from = 9, 
      to   = 21,
      col="red" , add=TRUE)
par(new=TRUE)
legend("topleft",
       c("LWage_LowAbility","LWage_HighAbility"),
       fill=c("blue","red"))

Ejercicio aplicado 2 captulo 6

rm(list = ls())

library(carData)
library(car)
library(MASS)
library(readr)


nombres1 <- c("person_id", "education", "log_wage", "expirience", "time")
nombres2 <- c("ability", "mothers_ed", "fathers_ed", "brokenhome", "siblings")


base1 <- read.csv("time_var(ejercicioapl5.1).cvs", header = FALSE, sep = "", col.names = nombres1)
base2 <- read.csv("time_invar(ejercicioapl5.1).cvs",header = FALSE, sep = "", col.names = nombres2)



conteo <- as.data.frame(table(base1[,1]))    

base3 <- data.frame(base2, ntimes = conteo[,2])   
base3 <- as.data.frame(lapply(base3, rep, base3$ntimes))  
base3 <- data.frame(base3[,1:5])   
tabla6 <- data.frame(base1, base3)  
names(tabla6)

x1 <-data.frame(const=rep(1, each =17919), edu = tabla6$education, lw = tabla6$log_wage, expe = tabla6$expirience, t = tabla6$time )

x2 <- data.frame(hab = tabla6$ability, maedu = tabla6$mothers_ed, paedu = tabla6$fathers_ed, hroto = tabla6$brokenhome, bros = tabla6$siblings)

X <- data.frame(x1, x2)  
names(X)

reg <- lm(lw ~ edu + expe + hab + maedu + paedu + bros, data = X )
summary(reg)
SRC <- sum(residuals(reg)^2)

reghr <- lm(lw ~ edu + expe + hab + maedu + paedu + bros, data = X[X[,"hroto"]==1,] )
summary(reghr)
SRChr <- sum(residuals(reghr)^2)


regnr <- lm(lw ~ edu + expe + hab + maedu + paedu + bros, data = X[X[,"hroto"]==0,])
summary(regnr)
SRCnr <- sum(residuals(regnr)^2)

db <- coef(regnr) - coef(reghr)
vdb <- vcov(regnr) + vcov(reghr)
X_c <- t(db)%*%solve(vdb)%*%(db) 
X_t <- qchisq(0.05, 7, lower.tail=FALSE)
X_c 
X_t 
chow <- ((SRC-(SRChr + SRCnr))/7)/((SRChr + SRCnr)/(17919-14)) 
c <- qf(0.05, 7 , 17919 - 14, lower.tail=FALSE)

Ejercicio aplicado 3 captulo 6

rm(list = ls()) 
library(pacman) 
p_load(tidyverse, car, AER, sandwich, dplyr, MASS, aod) 
library(ggplot2)
install.packages("gap")
library(gap)
Table64<- read_csv("http://pages.stern.nyu.edu/~wgreene/Text/Edition7/TableF6-4.csv") 
names(Table64)

Modelo1<- lm( (Q/A) ~ log (K), Table64)

Table64<- transform(Table64, a=(-1/K), b = (1/K))

Modelo2<- lm((Q/A) ~ (a), Table64)

Modelo3<- lm(log(Q/A) ~ log(K), Table64)

Table64<- transform(Table64, b=(1/K))

Modelo4<- lm(log(Q/A) ~ (a), Table64)


coef(Modelo1)
coef(Modelo2)
coef(Modelo3)
coef(Modelo4)
Table64 <- mutate(Table64,
       mark = ifelse(Table64$YEAR%in%c(1943:1949),1,0))

Grafica<-ggplot() +
  geom_point(Table64, mapping = aes(x=K, y=(Q/A))) +
  geom_point(filter(Table64, mark == 1), mapping = aes(x=K, y=(Q/A)), colour = "Red") + 
  geom_point(filter(Table64, mark == 0), mapping = aes(x=K, y=(Q/A)), colour = "Blue") +
  labs(title="Producci?n per c?pita Vs Capital ")+ theme_get()

Grafica


Table64
Table64<- transform(Table64, a=(-1/K), b = (1/K))
Modelo1<-lm( (Q/A) ~ log (K) + log(K) + mark + mark*log(K) , Table64)
Modelo2<-lm( (Q/A) ~ a + mark + mark*a , Table64)
Modelo3<-lm( log(Q/A) ~ log(K) + mark + mark*log(K) , Table64)
Modelo4<-lm( log(Q/A) ~ b+ mark + mark*b , Table64)

coef(Modelo1)
coef(Modelo2)
coef(Modelo3)
coef(Modelo4)



X1<- Table64$K[1:34]
X1<- log(X1)

a1<-Table64$Q[1:34]
b1<- Table64$A[1:34]
y1<- (a1/b1)

X2<- Table64$K[35:41]
X2<- log(X2)

a2<-Table64$Q[35:41]
b2<- Table64$A[35:41]
y2<- (a2/b2)

cwtes1<- chow.test(y2,X2,y1,X1)
cwtes1


X1<- Table64$K[1:34]
X1<- -1/X1

a1<-Table64$Q[1:34]
b1<- Table64$A[1:34]
y1<- (a1/b1)

X2<- Table64$K[35:41]
X2<- -1/X2

a2<-Table64$Q[35:41]
b2<- Table64$A[35:41]
y2<- (a2/b2)

cwtes2<- chow.test(y2,X2,y1,X1)
cwtes2



X1<- Table64$K[1:34]
X1<- log(X1)

a1<-Table64$Q[1:34]
b1<- Table64$A[1:34]
y1<- log(a1/b1)

X2<- Table64$K[35:41]
X2<- log(X2)

a2<-Table64$Q[35:41]
b2<- Table64$A[35:41]
y2<- log(a2/b2)

cwtes3<- chow.test(y2,X2,y1,X1)
cwtes3


X1<- Table64$K[1:34]
X1<- 1/X1

a1<-Table64$Q[1:34]
b1<- Table64$A[1:34]
y1<- log(a1/b1)

X2<- Table64$K[35:41]
X2<- 1/X2

a2<-Table64$Q[35:41]
b2<- Table64$A[35:41]
y2<- log(a2/b2)

cwtes4<- chow.test(y2,X2,y1,X1)
cwtes4



Estadisticos<-c(cwtes1[1], cwtes2[1],cwtes3[1], cwtes4[1])
names(Estadisticos)<- c("FstatMod1", "FstatMod2", "FstatMod3", "FstatMod4")
names(Estadisticos)

Estadisticos

qf(0.05, 2, 37, lower.tail=F)

Ejercicio aplicado 4 captulo 6

rm(list = ls()) 
library(pacman) 
p_load(tidyverse, car, AER, sandwich, dplyr, MASS, aod, gap) 
tabla64 <- read_csv("tabla_6_9.csv")
names(tabla64)


tabla64 <- transform(tabla64, ship_B = ifelse(tabla64$Barco == "B",1,0), ship_C = ifelse(tabla64$Barco == "C",1,0)
                     , ship_D = ifelse(tabla64$Barco == "D",1,0), ship_E = ifelse(tabla64$Barco == "E",1,0), per_2 = ifelse(tabla64$Periodo == 2, 1, 0),
                     per_3 = ifelse(tabla64$Periodo == 3, 1, 0), per_4 = ifelse(tabla64$Periodo == 4, 1, 0))


reg <- lm(Accidentes ~ ship_B + ship_C + ship_D + ship_E + per_2 + per_3 + per_4 , data = tabla64)
summary(reg)
SRC <- sum(residuals(reg)^2)


regb <- lm(Accidentes ~ ship_B + ship_C + ship_D + ship_E, data = tabla64)
summary(regb)
SRCb <- sum(residuals(regb)^2)


regt <- lm(Accidentes ~ per_2 + per_3 + per_4 , data = tabla64)
summary(reg)
SRCt <- sum(residuals(regt)^2)

F_barco <- ((SRCb - SRC)/4)/(SRC/(20-8))
F_barco

qf(0.05, 4, 12, lower.tail=F)

F_tiempo <- ((SRCt - SRC)/3)/(SRC/(20-8))
F_tiempo
qf(0.05, 3, 12, lower.tail=F)

Ejercicios Wooldrige Computacionales (Introductory econometrics…)

Ejercicio computacional C1 capítulo 13

library(dplyr)
library(car)
library(haven)
library(base)



fer <- read_stata("fertil1.dta")
str(fer)
head(fer)
tail(fer)


regK<-lm(kids~ educ+ age +I(age**2)+black+east+northcen+west+farm+othrural+town+smcity+y74+y76+y78+y80+y82+y84,fer)
summary(regK)


linearHypothesis(regK, c("farm=0","othrural=0","town=0","smcity=0"), test = "F")


qf(0.05, 4, (1115 - 4), lower.tail=F)   



linearHypothesis(regK, c("east=0","northcen=0","west=0"), test = "F")


qf(0.05, 3, (1114 - 3), lower.tail=F)


u<-(regK$residuals)**2
regu<-lm(u~ y74+y76+y78+y80+y82+y84,fer)
summary(regu)    


linearHypothesis(regu, c("y74=0","y76=0","y78=0","y80=0","y82=0","y84=0"), test = "F")


qf(0.05, 6, (1128 - 6), lower.tail=F)


qf(0.01, 6, (1128 - 6), lower.tail=F)

regKeduc<-lm(kids~ educ+ age +I(age**2)+black+east+northcen+west+farm+othrural+town+smcity+y74+y76+y78+y80+y82+y84+educ:y74+educ:y76+educ:y78+educ:y80+educ:y82+educ:y84,fer)
summary(regKeduc)

linearHypothesis(regKeduc, c("educ:y74 =0","educ:y76=0","educ:y78=0","educ:y80=0","educ:y82=0","educ:y84=0"), test = "F")

qf(0.1, 6, (1111 - 6), lower.tail=F)



coef(regKeduc)

linearHypothesis(regKeduc, c("educ:y78=0","educ:y82=0","educ:y84=0"), test = "F")

qf(0.1, 3, (1108 - 3), lower.tail=F)

Ejercicio computacional C2 capítulo 13

rm(list = ls())

library("wooldridge")
library("dplyr")
library("base")

help("cps78_85")  
str(cps78_85)

reg1 <- lm(lwage ~ 
             y85 + educ + y85educ + exper + expersq + union
           + female + y85fem
             , data = cps78_85)
summary(reg1)
coef(reg1)

reg2 <- lm(lwage ~ 
             y85 + educ + I(y85*(educ-12)) + exper + expersq + union
           + female + y85fem
           , data = cps78_85)
summary(reg2)


confint(reg2)


w78 <- subset(cps78_85, year==78)
w85 <- subset(cps78_85, year==85)
rw85 <- mutate(w85, rwage=lwage-log(1.65))
rw78 <- mutate(w78, rwage=lwage)
base1 <- rbind(rw85,rw78)

reg3 <- lm(rwage ~ 
             y85 + educ + y85educ + exper + expersq + union
           + female + y85fem
           , data = base1)
summary(reg3)
summary(reg1)


ssr1=sum((reg1$residuals)^2)
ssr1
ssr2=sum((reg2$residuals)^2)
ssr2



sst1=sum((base1$lwage -mean(base1$lwage))^2)
sst1
sst2=sum((base1$rwage-mean(base1$rwage))^2)
sst2



count(w78, union)
count(w85, union)
u78= 168/550
u85= 96/534
u78
u85



reg_f <- lm(lwage ~ 
             y85 + educ + y85educ + exper + expersq + union +
             y85union  + female + y85fem
           , data = cps78_85)
summary(reg_f)

Ejercicios Wooldridge (Econometric analysis…)

Problema 6.7 Aplicado

install.packages("wooldridge")
library(wooldridge)
library(car)
library(MASS)
library(readr)


data("hprice3")
names(hprice3)

 

reg81 <- lm(lprice ~ ldist , data = hprice3[hprice3[,"y81"]==1,])
summary(reg81)


regb <- lm(lprice ~ (y81 + ldist)^2, data = hprice3)
summary(regb)




R <- matrix( 0, nrow = 2, ncol = 4)
R[1, 3] <- 1
R[2, 4] <- 1
q <- matrix (c(0, 0))

R
q


car::linearHypothesis(regb, R,q)



regc <- lm(lprice ~ (y81 + ldist)^2 + linst + linstsq + larea + lland + age + agesq + rooms + baths, data = hprice3)
summary(regc)



R1 <- matrix( 0, nrow = 2, ncol = 12)
R1[1, 3] <- 1
R1[2, 12] <- 1
q <- matrix (c(0, 0))

R1
q


car::linearHypothesis(regc, R1, q)

Problema 6.11 Aplicado

rm(list = ls())
library(pacman)
library(aod)
library(MASS)
library(readxl)
p_load(tidyverse, car, AER, sandwich) 
cps78_85 <- read_excel("cps78_85.xls")
View(cps78_85)
regresion <- lm(lwage~y85+educ+y85educ+exper+expersq+union+female+y85female, data=cps78_85)
summary(regresion)


lwage85 <- cps78_85[551:1084 , 9]
lwage85_def <- lwage85-log(1.65)
x <- cps78_85[1:550,9]
lwage_def <- rbind(x,lwage85_def)
datos <- cbind(cps78_85,lwage_def)
names(datos)[16] <- "lwdef" 
reg_def <- lm(lwdef~y85+educ+y85educ+exper+expersq+union+female+y85female, data=datos)
summary(reg_def)

err <- residuals(reg_def)
ersq <- I(err^2) # Errores al cuadrado
dat <- cbind(datos,ersq)
r <- lm(ersq~y85, data=dat)
summary(r)

y85ed <- cps78_85[551:1084,14]
aux <- y85ed-12
aux2 <- cps78_85[1:550,14]
y85edmod <-rbind(aux2,aux)
da<-cbind(cps78_85,y85edmod)
names(da)[16] <- "y85educmod"
re <- lm(lwage~y85+educ+y85educmod+exper+expersq+union+female+y85female, data=da)
M<-summary(re)$coef
 
Media <-M[2,1]
se <- M[2,2]
In<-Media+(1.96*se)
Sup<-Media-(1.96*se)

Literatura diferencias en diferencias