1、微观计量经济学模型ModelofMicroeconometrics微观计量经济学模型(Model of Microeconometrics)1.1 Generalized Linear ModelsThree aspects of the linear regression model for a conditionally normally distributed response y are:(1)The linear predictor through which .(2) is (3)GLMs: extends (2)and(3) to more general families of
2、 distributions for y. Specifically, may follow a density:canonical parameter, depends on the linear predictor.:dispersion parameter, is often known.Also and are related by a monotonic transformation,Called the link function of the GLM.Selected GLM families and their canonical linkFamilyCanonical lin
3、kNamebinomiallogitgaussianidentitypoissonlog1.2 Binary Dependent VariablesModel:In the probit case: equals the standard normal CDFIn the logit case: equals the logistic CDFExample:(1)DataConsidering female labor participation for a sample of 872 women from Switzerland.The dependent variable: partici
4、pationThe explain variables:income,age,education,youngkids,oldkids,foreignyesandage2.R:library(AER)data(SwissLabor)summary(SwissLabor)participation income age education no :471 Min. : 7.187 Min. :2.000 Min. : 1.000 yes:401 1st Qu.:10.472 1st Qu.:3.200 1st Qu.: 8.000 Median :10.643 Median :3.900 Medi
5、an : 9.000 Mean :10.686 Mean :3.996 Mean : 9.307 3rd Qu.:10.887 3rd Qu.:4.800 3rd Qu.:12.000 Max. :12.376 Max. :6.200 Max. :21.000 youngkids oldkids foreign Min. :0.0000 Min. :0.0000 no :656 1st Qu.:0.0000 1st Qu.:0.0000 yes:216 Median :0.0000 Median :1.0000 Mean :0.3119 Mean :0.9828 3rd Qu.:0.0000
6、3rd Qu.:2.0000 Max. :3.0000 Max. :6.0000 (2) EstimationR:swiss_prob=glm(participation.+I(age2),data=SwissLabor,family=binomial(link=probit)summary(swiss_prob)Call:glm(formula = participation . + I(age2), family = binomial(link = probit), data = SwissLabor)Deviance Residuals: Min 1Q Median 3Q Max -1.
7、9191 -0.9695 -0.4792 1.0209 2.4803 Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 3.74909 1.40695 2.665 0.00771 * income -0.66694 0.13196 -5.054 4.33e-07 *age 2.07530 0.40544 5.119 3.08e-07 *education 0.01920 0.01793 1.071 0.28428 youngkids -0.71449 0.10039 -7.117 1.10e-12 *oldkids -0
8、.14698 0.05089 -2.888 0.00387 * foreignyes 0.71437 0.12133 5.888 3.92e-09 *I(age2) -0.29434 0.04995 -5.893 3.79e-09 *-Signif. codes: 0 * 0.001 * 0.01 * 0.05 . 0.1 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 1203.2 on 871 degrees of freedomResidual deviance: 1017.2 on 86
9、4 degrees of freedomAIC: 1033.2Number of Fisher Scoring iterations: 4(3)VisualizationPlotting participation versus ageR:plot(participationage,data=SwissLabor,ylevels=2:1)(4)EffectsAverage marginal effects:The average of the sample marginal effects: R:fav=mean(dnorm(predict(swiss_prob,type=link)fav*c
10、oef(swiss_prob)(Intercept) income age education youngkids 1.241929965 -0.220931858 0.687466185 0.006358743 -0.236682273 oldkids foreignyes I(age2) -0.048690170 0.236644422 -0.097504844The average marginal effects at the average regressor:R:av=colMeans(SwissLabor,-c(1,7)av=data.frame(rbind(swiss=av,f
11、oreign=av),foreign=factor(c(no,yes)av=predict(swiss_prob,newdata=av,type=link)av=dnorm(av)avswiss*coef(swiss_prob)-7avforeign*coef(swiss_prob)-7swiss: (Intercept) income age education youngkids 1.495137092 -0.265975880 0.827628145 0.007655177 -0.284937521 oldkids I(age2) -0.058617218 -0.117384323For
12、eign:(Intercept) income age education youngkids 1.136517140 -0.202179551 0.629115268 0.005819024 -0.216593099 oldkids I(age2) -0.044557434 -0.089228804(5)Goodness of fit and predictionPseudo-R2:as the log-likelihood for the fitted model, as the log-likelihood for the model containing only a constant
13、 term.R: swiss_prob0=update(swiss_prob,formula=.1)1-as.vector(logLik(swiss_prob)/logLik(swiss_prob0)1 0.1546416Percent correctly predicted:R:table(true=SwissLabor$participation,pred=round(fitted(swiss_prob) predtrue 0 1no 337 134yes 146 25567.89%ROC curve:TPR(c):the number of women participating in
14、the labor force that are classified as participating compared with the total number of women participating.FPR(c):the number of women not participating in the labor force that are classified as participating compared with the total number of women not participating.R:library(ROCR)pred=prediction(fit
15、ted(swiss_prob),SwissLabor$participation)plot(performance(pred,acc)plot(performance(pred,tpr,fpr)abline(0,1,lty=2)Extensions: Multinomial responsesFor illustrating the most basic version of the multinomial logit model, a model with only individual-specific covariates,.data(BankWages)It contains, for
16、 employees of a US bank, an ordered factor job with levels custodial, admin(for administration), and manage (for management), to be modeled as afunction of education (in years) and a factor minority indicating minority status. There also exists a factor gender, but since there are no women in the ca
17、tegory custodial, only a subset of the data corresponding to males is used for parametric modeling below.summary(BankWages) job education gender minority custodial: 27 Min. : 8.00 male :258 no :370 admin :363 1st Qu.:12.00 female:216 yes:104 manage : 84 Median :12.00 Mean :13.49 3rd Qu.:15.00 Max. :
18、21.00 summary(BankWages)edcat - factor(BankWages$education)edcatlevels(edcat)3:10 - rep(c(14-15, 16-18, 19-21),+ c(2, 3, 3)head(edcat)tab - xtabs( edcat + job, data = BankWages)head(tab)prop.table(tab, 1)head(BankWages)library(nnet)bank_mn2 |z|) (Intercept) 0.2649934 0.0937222 2.8274 0.004692 * qual
19、ity 0.4717259 0.0170905 27.6016 2.2e-16 *skiyes 0.4182137 0.0571902 7.3127 2.619e-13 *income -0.1113232 0.0195884 -5.6831 1.323e-08 *userfeeyes 0.8981653 0.0789851 11.3713 2.2e-16 *costC -0.0034297 0.0031178 -1.1001 0.271309 costS -0.0425364 0.0016703 -25.4667 2.2e-16 *costH 0.0361336 0.0027096 13.3
20、353 0 and underdispersion to a 0. Common specifications of the transformation function h are h() = 2 or h() = . The former corresponds to a negative binomial (NB) model (see below) with quadratic variance function (called NB2 by Cameron and Trivedi 1998), the latter to an NB model with linear varian
21、ce function (called NB1 by Cameron and Trivedi 1998). In the statistical literature, the reparameterization Var(yi|xi) = (1 + a) i = dispersion iof the NB1 model is often called a quasi-Poisson model with dispersion parameter.R: dispersiontest(rd_pois) Overdispersion testdata: rd_pois z = 2.4116, p-value = 0.007941alternative hypothesis: true dispersion is greater than 1 sample estimates:dispersion 6.5658R:dispersiontest(rd_pois, trafo = 2) Overdispersion testdata: rd_pois z = 2.9381, p-value = 0.001651alternative hypothesis: true alpha is greater than 0 sample estimates: alpha 1.316051Bo
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1