Abstract
This is an undergrad student level exercise for class use. Kmenta’s dataset and code from the systemfit package.This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
License: CC BY-SA 4.0
Sugestão de citação: FIGUEIREDO, Adriano Marcos Rodrigues.
Econometria: exercício do pacote systemfit
- Sistemas de
equações simultâneas. Campo Grande-MS,Brasil: RStudio/Rpubs, 2021.
Disponível em http://rpubs.com/amrofi/exercicio_systemfit.
Seja o sistema de equações do tipo:
Equação de demanda:
\[ \operatorname{consump} = \alpha_d + \beta_{1}(\operatorname{price}) + \beta_{2}(\operatorname{income}) + \varepsilon_d \]
Equação de oferta:
\[ \operatorname{consump} = \alpha_s + \gamma_{1}(\operatorname{price}) + \gamma_{2}(\operatorname{farmPrice}) + \gamma_{3}(\operatorname{trend}) + \varepsilon_s \]
library(systemfit)
data("Kmenta")
eqDemand <- consump ~ price + income
eqSupply <- consump ~ price + farmPrice + trend
inst <- ~income + farmPrice + trend
system <- list(demand = eqDemand, supply = eqSupply)
# OLS estimation:
fitOls <- systemfit(system, data = Kmenta)
round(coef(summary(fitOls)), digits = 4)
Estimate Std. Error t value Pr(>|t|)
demand_(Intercept) 99.8954 7.5194 13.2851 0.0000
demand_price -0.3163 0.0907 -3.4882 0.0028
demand_income 0.3346 0.0454 7.3673 0.0000
supply_(Intercept) 58.2754 11.4629 5.0838 0.0001
supply_price 0.1604 0.0949 1.6901 0.1104
supply_farmPrice 0.2481 0.0462 5.3723 0.0001
supply_trend 0.2483 0.0975 2.5462 0.0216
# 2SLS estimation:
fit2sls <- systemfit(system, method = "2SLS", inst = inst, data = Kmenta)
round(coef(summary(fit2sls)), digits = 4)
Estimate Std. Error t value Pr(>|t|)
demand_(Intercept) 94.6333 7.9208 11.9474 0.0000
demand_price -0.2436 0.0965 -2.5243 0.0218
demand_income 0.3140 0.0469 6.6887 0.0000
supply_(Intercept) 49.5324 12.0105 4.1241 0.0008
supply_price 0.2401 0.0999 2.4023 0.0288
supply_farmPrice 0.2556 0.0473 5.4096 0.0001
supply_trend 0.2529 0.0997 2.5380 0.0219
# 3SLS estimation:
fit3sls <- systemfit(system, method = "3SLS", inst = inst, data = Kmenta)
round(coef(summary(fit3sls)), digits = 4)
Estimate Std. Error t value Pr(>|t|)
demand_(Intercept) 94.6333 7.9208 11.9474 0.0000
demand_price -0.2436 0.0965 -2.5243 0.0218
demand_income 0.3140 0.0469 6.6887 0.0000
supply_(Intercept) 52.1972 11.8934 4.3888 0.0005
supply_price 0.2286 0.0997 2.2934 0.0357
supply_farmPrice 0.2282 0.0440 5.1861 0.0001
supply_trend 0.3611 0.0729 4.9546 0.0001
# Iterated 3SLS estimation:
fitI3sls <- systemfit(system, method = "3SLS", inst = inst, data = Kmenta, maxit = 250)
round(coef(summary(fitI3sls)), digits = 4)
Estimate Std. Error t value Pr(>|t|)
demand_(Intercept) 94.6333 7.9208 11.9474 0.0000
demand_price -0.2436 0.0965 -2.5243 0.0218
demand_income 0.3140 0.0469 6.6887 0.0000
supply_(Intercept) 52.6618 12.8051 4.1126 0.0008
supply_price 0.2266 0.1075 2.1086 0.0511
supply_farmPrice 0.2234 0.0468 4.7756 0.0002
supply_trend 0.3800 0.0720 5.2771 0.0001
summary(fitOls)
systemfit results
method: OLS
N DF SSR detRCov OLS-R2 McElroy-R2
system 40 33 155.883 4.43485 0.709298 0.557559
N DF SSR MSE RMSE R2 Adj R2
demand 20 17 63.3317 3.72539 1.93013 0.763789 0.735999
supply 20 16 92.5511 5.78444 2.40509 0.654807 0.590084
The covariance matrix of the residuals
demand supply
demand 3.72539 4.13696
supply 4.13696 5.78444
The correlations of the residuals
demand supply
demand 1.000000 0.891179
supply 0.891179 1.000000
OLS estimates for 'demand' (equation 1)
Model Formula: consump ~ price + income
Estimate Std. Error t value Pr(>|t|)
(Intercept) 99.8954229 7.5193621 13.28509 2.0906e-10 ***
price -0.3162988 0.0906774 -3.48818 0.0028153 **
income 0.3346356 0.0454218 7.36729 1.0999e-06 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.930127 on 17 degrees of freedom
Number of observations: 20 Degrees of Freedom: 17
SSR: 63.33165 MSE: 3.725391 Root MSE: 1.930127
Multiple R-Squared: 0.763789 Adjusted R-Squared: 0.735999
OLS estimates for 'supply' (equation 2)
Model Formula: consump ~ price + farmPrice + trend
Estimate Std. Error t value Pr(>|t|)
(Intercept) 58.2754312 11.4629099 5.08383 0.00011056 ***
price 0.1603666 0.0948839 1.69013 0.11038810
farmPrice 0.2481333 0.0461879 5.37226 6.2274e-05 ***
trend 0.2483023 0.0975178 2.54623 0.02156713 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.405087 on 16 degrees of freedom
Number of observations: 20 Degrees of Freedom: 16
SSR: 92.551058 MSE: 5.784441 Root MSE: 2.405087
Multiple R-Squared: 0.654807 Adjusted R-Squared: 0.590084
summary(fit2sls)
systemfit results
method: 2SLS
N DF SSR detRCov OLS-R2 McElroy-R2
system 40 33 162.362 4.36424 0.697214 0.548127
N DF SSR MSE RMSE R2 Adj R2
demand 20 17 65.7291 3.86642 1.96632 0.754847 0.726005
supply 20 16 96.6332 6.03958 2.45756 0.639582 0.572004
The covariance matrix of the residuals
demand supply
demand 3.86642 4.35744
supply 4.35744 6.03958
The correlations of the residuals
demand supply
demand 1.000000 0.901724
supply 0.901724 1.000000
2SLS estimates for 'demand' (equation 1)
Model Formula: consump ~ price + income
Instruments: ~income + farmPrice + trend
Estimate Std. Error t value Pr(>|t|)
(Intercept) 94.6333039 7.9208383 11.94738 1.0762e-09 ***
price -0.2435565 0.0964843 -2.52431 0.021832 *
income 0.3139918 0.0469437 6.68869 3.8109e-06 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.966321 on 17 degrees of freedom
Number of observations: 20 Degrees of Freedom: 17
SSR: 65.729088 MSE: 3.866417 Root MSE: 1.966321
Multiple R-Squared: 0.754847 Adjusted R-Squared: 0.726005
2SLS estimates for 'supply' (equation 2)
Model Formula: consump ~ price + farmPrice + trend
Instruments: ~income + farmPrice + trend
Estimate Std. Error t value Pr(>|t|)
(Intercept) 49.5324417 12.0105264 4.12409 0.00079536 ***
price 0.2400758 0.0999339 2.40235 0.02878451 *
farmPrice 0.2556057 0.0472501 5.40964 5.7854e-05 ***
trend 0.2529242 0.0996551 2.53800 0.02192877 *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.457555 on 16 degrees of freedom
Number of observations: 20 Degrees of Freedom: 16
SSR: 96.633244 MSE: 6.039578 Root MSE: 2.457555
Multiple R-Squared: 0.639582 Adjusted R-Squared: 0.572004
summary(fit3sls)
systemfit results
method: 3SLS
N DF SSR detRCov OLS-R2 McElroy-R2
system 40 33 173.643 1.0332 0.676177 0.786468
N DF SSR MSE RMSE R2 Adj R2
demand 20 17 65.7291 3.86642 1.96632 0.754847 0.726005
supply 20 16 107.9138 6.74461 2.59704 0.597508 0.522041
The covariance matrix of the residuals used for estimation
demand supply
demand 3.86642 4.35744
supply 4.35744 6.03958
The covariance matrix of the residuals
demand supply
demand 3.86642 5.00443
supply 5.00443 6.74461
The correlations of the residuals
demand supply
demand 1.00000 0.97999
supply 0.97999 1.00000
3SLS estimates for 'demand' (equation 1)
Model Formula: consump ~ price + income
Instruments: ~income + farmPrice + trend
Estimate Std. Error t value Pr(>|t|)
(Intercept) 94.6333039 7.9208383 11.94738 1.0762e-09 ***
price -0.2435565 0.0964843 -2.52431 0.021832 *
income 0.3139918 0.0469437 6.68869 3.8109e-06 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.966321 on 17 degrees of freedom
Number of observations: 20 Degrees of Freedom: 17
SSR: 65.729088 MSE: 3.866417 Root MSE: 1.966321
Multiple R-Squared: 0.754847 Adjusted R-Squared: 0.726005
3SLS estimates for 'supply' (equation 2)
Model Formula: consump ~ price + farmPrice + trend
Instruments: ~income + farmPrice + trend
Estimate Std. Error t value Pr(>|t|)
(Intercept) 52.1972042 11.8933720 4.38876 0.00045780 ***
price 0.2285892 0.0996732 2.29339 0.03570648 *
farmPrice 0.2281580 0.0439938 5.18614 9.0087e-05 ***
trend 0.3611384 0.0728894 4.95461 0.00014343 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.597039 on 16 degrees of freedom
Number of observations: 20 Degrees of Freedom: 16
SSR: 107.913821 MSE: 6.744614 Root MSE: 2.597039
Multiple R-Squared: 0.597508 Adjusted R-Squared: 0.522041
summary(fitI3sls)
systemfit results
method: iterated 3SLS
convergence achieved after 6 iterations
N DF SSR detRCov OLS-R2 McElroy-R2
system 40 33 178.16 0.983079 0.667753 0.814118
N DF SSR MSE RMSE R2 Adj R2
demand 20 17 65.7291 3.86642 1.96632 0.754847 0.726005
supply 20 16 112.4313 7.02696 2.65084 0.580659 0.502033
The covariance matrix of the residuals used for estimation
demand supply
demand 3.86642 5.11719
supply 5.11719 7.02683
The covariance matrix of the residuals
demand supply
demand 3.86642 5.11723
supply 5.11723 7.02696
The correlations of the residuals
demand supply
demand 1.000000 0.981741
supply 0.981741 1.000000
3SLS estimates for 'demand' (equation 1)
Model Formula: consump ~ price + income
Instruments: ~income + farmPrice + trend
Estimate Std. Error t value Pr(>|t|)
(Intercept) 94.6333039 7.9208383 11.94738 1.0762e-09 ***
price -0.2435565 0.0964843 -2.52431 0.021832 *
income 0.3139918 0.0469437 6.68869 3.8109e-06 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.966321 on 17 degrees of freedom
Number of observations: 20 Degrees of Freedom: 17
SSR: 65.729088 MSE: 3.866417 Root MSE: 1.966321
Multiple R-Squared: 0.754847 Adjusted R-Squared: 0.726005
3SLS estimates for 'supply' (equation 2)
Model Formula: consump ~ price + farmPrice + trend
Instruments: ~income + farmPrice + trend
Estimate Std. Error t value Pr(>|t|)
(Intercept) 52.6618215 12.8051061 4.11256 0.00081480 ***
price 0.2265865 0.1074593 2.10858 0.05109577 .
farmPrice 0.2233723 0.0467735 4.77562 0.00020634 ***
trend 0.3800062 0.0720098 5.27715 7.5166e-05 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.650841 on 16 degrees of freedom
Number of observations: 20 Degrees of Freedom: 16
SSR: 112.431326 MSE: 7.026958 Root MSE: 2.650841
Multiple R-Squared: 0.580659 Adjusted R-Squared: 0.502033
Henningsen, Arne; Hamann, Jeff D. (2007). systemfit: A Package for Estimating Systems of Simultaneous Equations in R. Journal of Statistical Software 23(4), 1-40. URL http://www.jstatsoft.org/v23/i04/.