微观计量经济学模型(Model-of-Microeconometrics)
- 格式:doc
- 大小:155.00 KB
- 文档页数:17
微观计量经济学模型(Model of Microeconometrics )1.1 Generalized Linear Mod elsThree aspects of the linear regression model for a conditionally normally distributed response y are:(1) The linear predictor βηT i i x = through which )|(i i i x y E =μ. (2) i i x y | is ),(2σμi N (3) i i ημ=GLMs: extends (2)and(3) to more general families of distributions for y. Specifically, i i x y | may follow a density:⎭⎬⎫+⎩⎨⎧-=);()(exp ),;(φφθθφθy c b y y fθ:canonical parameter, depends on the linear predictor.φ:dispersion parameter, is often known.Also i η and i μ are related by a monotonic transformation,i i g ημ=)(Called the link function of the GLM.Selected GLM families and their canonical link1.2 Binary Depend ent VariablesModel:n i x F p x y E T i i i i ,......2,1),()|(===βIn the probit case: F equals the standard normal CDF In the logit case: F equals the logistic CDFExample:(1)DataConsidering female labor participation for a sample of 872 women from Switzerland.The dependent variable: participation The explain variables:income,age,education,youngkids,oldkids,foreignyesandage^2. R:library("AER")data("SwissLabor")summary(SwissLabor)participation income age educationno :471 Min. : 7.187 Min. :2.000 Min. : 1.000yes:401 1st Qu.:10.472 1st Qu.:3.200 1st Qu.: 8.000Median :10.643 Median :3.900 Median : 9.000Mean :10.686 Mean :3.996 Mean : 9.3073rd Qu.:10.887 3rd Qu.:4.800 3rd Qu.:12.000Max. :12.376 Max. :6.200 Max. :21.000 youngkids oldkids foreignMin. :0.0000 Min. :0.0000 no :6561st Qu.:0.0000 1st Qu.:0.0000 yes:216Median :0.0000 Median :1.0000Mean :0.3119 Mean :0.98283rd Qu.:0.0000 3rd Qu.:2.0000Max. :3.0000 Max. :6.0000(2) EstimationR:swiss_prob=glm(participation~.+I(age^2),data=SwissLabor,family=binomial(link="pro bit"))summary(swiss_prob)Call:glm(formula = participation ~ . + I(age^2), family = binomial(link = "probit"),data = SwissLabor)Deviance Residuals:Min 1Q Median 3Q Max-1.9191 -0.9695 -0.4792 1.0209 2.4803Coefficients: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.28428youngkids -0.71449 0.10039 -7.117 1.10e-12 ***oldkids -0.14698 0.05089 -2.888 0.00387 **foreignyes 0.71437 0.12133 5.888 3.92e-09 ***I(age^2) -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 864 degrees of freedomAIC: 1033.2Number of Fisher Scoring iterations: 4(3)VisualizationPlotting participation versus ageR:plot(participation~age,data=SwissLabor,ylevels=2:1)(4) Effectsj T i ijT i ij i i x x x x x y E ββφβ⋅=∂Φ∂=∂∂)()()|(Average marginal effects:The average of the sample marginal effects: j Ti n ix nββφ⋅∑)(1 R:fav=mean(dnorm(predict(swiss_prob,type="link"))) fav*coef(swiss_prob)(Intercept) income age education youngkids 1.241929965 -0.220931858 0.687466185 0.006358743 -0.236682273 oldkids foreignyes I(age^2) -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,foreign=av),foreign=factor(c("no","yes"))) av=predict(swiss_prob,newdata=av,type="link") av=dnorm(av)av["swiss"]*coef(swiss_prob)[-7] av["foreign"]*coef(swiss_prob)[-7]swiss:(Intercept) income age education youngkids 1.495137092 -0.265975880 0.827628145 0.007655177 -0.284937521 oldkids I(age^2) -0.058617218 -0.117384323Foreign:(Intercept) income age education youngkids 1.136517140 -0.202179551 0.629115268 0.005819024 -0.216593099 oldkids I(age^2) -0.044557434 -0.089228804(5) Goodness of fit and prediction Pseudo-R2:)()ˆ(12ββλλ-=R)ˆ(βλas the log-likelihood for the fitted model, )(βλ)ˆ(βλas the log-likelihood for the model containing only a constant 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)))pred true 0 1 no 337 134 yes 146 25567.89% ROC curve:TPR(c):the number of women participating in the labor force that are classified as participating compared with the total number of womenparticipating.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:l ibrary("ROCR")pred=prediction(fitted(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 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 factorgender, but since there are no women in the category "custodial", only a subset of the data corresponding to males is used for parametric modeling below.summary(BankWages)job education gender minoritycustodial: 27 Min. : 8.00 male :258 no :370admin :363 1st Qu.:12.00 female:216 yes:104manage : 84 Median :12.00Mean :13.493rd Qu.:15.00Max. :21.00summary(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 <- multinom(job ~ education + minority+gender,data=BankWages,trace = FALSE)summary(bank_mn2)1.3 Regression Mod els for Count DataWe begin with the standard model for count data, a Poisson regression.Poisson Regression Model:)ex p()|(βμT i i i i x x y E ==Canonical link: the log link Example:Trips to Lake Somerville,Texas,1980. based on a survey administered to 2,000 registered leisure boat owners in 23 counties in eastern Texas.The dependent variable is trips, and we want to regress it on all further variables: a (subjective) quality ranking of the facility (quality), a factor indicating whether the individual engaged in water-skiing at the lake (ski),household income (income), a factor indicating whether the individual paid a user’s fee at the lake (userfee), and three cost variables (costC, costS,costH) representing opportunity costs. (1)Datadata("RecreationDemand") summary(RecreationDemand)trips quality ski income userfee Min. : 0.000 Min. :0.000 no :417 Min. :1.000 no :646 1st Qu.: 0.000 1st Qu.:0.000 yes:242 1st Qu.:3.000 yes: 13Median : 0.000 Median :0.000 Median :3.000 Mean : 2.244 Mean :1.419 Mean :3.853 3rd Qu.: 2.000 3rd Qu.:3.000 3rd Qu.:5.000 Max. :88.000 Max. :5.000 Max. :9.000 costC costS costH Min. : 4.34 Min. : 4.767 Min. : 5.70 1st Qu.: 28.24 1st Qu.: 33.312 1st Qu.: 28.96 Median : 41.19 Median : 47.000 Median : 42.38 Mean : 55.42 Mean : 59.928 Mean : 55.993rd Qu.: 69.67 3rd Qu.: 72.573 3rd Qu.: 68.56Max. :493.77 Max. :491.547 Max. :491.05head(RecreationDemand)trips quality ski income userfee costC costS costH1 0 0 yes 4 no 67.59 68.620 76.8002 0 0 no 9 no 68.86 70.936 84.7803 0 0 yes 5 no 58.12 59.465 72.1104 0 0 no 2 no 15.79 13.750 23.6805 0 0 yes 3 no 24.02 34.033 34.5476 0 0 yes 5 no 129.46 137.377 137.850(2) Estimationrd_pois=glm(trips~.,data=RecreationDemand,family=poisson) coeftest(rd_pois)z test of coefficients:Estimate Std. Error z value Pr(>|z|) (Intercept) 0.2649934 0.0937222 2.8274 0.004692 ** quality 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.3353 < 2.2e-16 *** Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘R:logLik(rd_pois)the log-likelihood of the fitted model:'log Lik.' -1529.431 (df=8)rbind(obs = table(RecreationDemand$trips)[1:10], exp = round(+ sapply(0:9, function(x) sum(dpois(x, fitted(rd_pois))))))0 1 2 3 4 5 6 7 8 9obs 417 68 38 34 17 13 11 2 8 1exp 277 146 68 41 30 23 17 13 10 7table(true=RecreationDemand$trips,pred=round(fitted(rd_nb)))NOT WELL(3)Dealing with overdispersionPoisson distribution has the property that the variance equals the mean. In econometrics, Poisson regressions are often plagued by overdispersion. One way of testing for overdispersion is to consider the alternative hypothesis(Cameron and Trivedi 1990)Var(yi|xi) = μi + a*h(μi)where h is a positive function of μi.Overdispersion corresponds to a > 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 variance function (called NB1 by Cameron and Trivedi 1998). In the statistical literature, the reparameterizationVar(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_poisz = 2.4116, p-value = 0.007941alternative hypothesis: true dispersion is greater than 1sample estimates:dispersion6.5658R:dispersiontest(rd_pois, trafo = 2)Overdispersion testdata: rd_poisz = 2.9381, p-value = 0.001651alternative hypothesis: true alpha is greater than 0sample estimates:alpha1.316051Both suggest that the Poisson model for the trips data is not wellspecified.One possible remedy is to consider a more flexible distribution that does not impose equality of mean and variance.The most widely used distribution in this context is the negative binomial. It may be considered a mixture distribution arising from a Poisson distribution with random scale, the latter following a gamma distribution. Its probability mass function isR: library("MASS")rd_nb <- glm.nb(trips ~ ., data = RecreationDemand)coeftest(rd_nb)z test of coefficients:Estimate Std. Error z value Pr(>|z|)(Intercept) -1.1219363 0.2143029 -5.2353 1.647e-07 ***quality 0.7219990 0.0401165 17.9976 < 2.2e-16 ***skiyes 0.6121388 0.1503029 4.0727 4.647e-05 ***income -0.0260588 0.0424527 -0.6138 0.53933userfeeyes 0.6691676 0.3530211 1.8955 0.05802 .costC 0.0480087 0.0091848 5.2270 1.723e-07 ***costS -0.0926910 0.0066534 -13.9314 < 2.2e-16 ***costH 0.0388357 0.0077505 5.0107 5.423e-07 ***---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘R:logLik(rd_nb)'log Lik.' -825.5576 (df=9)0 1 2 3 4 5 6 7 8 9obs 417 68 38 34 17 13 11 2 8 1exp 370 87 37 26 21 17 14 11 9 8(4)Zero-inflated Poisson and negative binomial modelsrbind(obs = table(RecreationDemand$trips)[1:10], exp = round(+ sapply(0:9, function(x) sum(dpois(x, fitted(rd_pois))))))0 1 2 3 4 5 6 7 8 9obs 417 68 38 34 17 13 11 2 8 1exp 277 146 68 41 30 23 17 13 1 0 7One such model is the zero-inflated Poisson (ZIP) model (Lambert 1992), which suggests a mixture specification with a Poisson count component and an additional point mass at zero. With I A(y) denoting the indicator function, the basic idea isf zeroinfl(y) = p i · I{0}(y) + (1 − p i) · f count(y; μi),we consider a regression of trips on all further variables for the count part (using a negative binomial distribution) and model the inflation part as a function of quality and income:library(pscl)rd_zinb = zeroinfl(trips ~ . | quality + income,data=RecreationDemand, dist="negbin")summary(rd_zinb )Call:zeroinfl(formula = trips ~ . | quality + income, data = RecreationDemand, dist = "negbin")Pearson residuals:Min 1Q Median 3Q Max-1.08885 -0.20037 -0.05696 -0.04509 40.01393Count model coefficients (negbin with log link):Estimate Std. Error z value Pr(>|z|)(Intercept) 1.096634 0.256679 4.272 1.93e-05 ***quality 0.168911 0.053032 3.185 0.001447 **skiyes 0.500694 0.134488 3.723 0.000197 ***income -0.069268 0.043800 -1.581 0.113775userfeeyes 0.542786 0.282801 1.919 0.054944 .costC 0.040445 0.014520 2.785 0.005345 **costS -0.066206 0.007745 -8.548 < 2e-16 ***costH 0.020596 0.010233 2.013 0.044146 *Log(theta) 0.190175 0.112989 1.683 0.092352 .Zero-inflation model coefficients (binomial with logit link):Estimate Std. Error z value Pr(>|z|)(Intercept) 5.7427 1.5561 3.691 0.000224 ***quality -8.3074 3.6816 -2.256 0.024041 *income -0.2585 0.2821 -0.916 0.359504---Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1Theta = 1.2095Number of iterations in BFGS optimization: 26Log-likelihood: -722 on 12 DfR:rbind(obs =table(RecreationDemand$trips)[1:10],exp=round(colSums(predict(rd_zin b, type = "prob")[,1:10])))0 1 2 3 4 5 6 7 8 9obs 417 68 38 34 17 13 11 2 8 1exp 433 47 35 27 20 16 12 10 8 7。