微观计量经济学模型Model of MicroeconometricsWord文档下载推荐.docx
《微观计量经济学模型Model of MicroeconometricsWord文档下载推荐.docx》由会员分享,可在线阅读,更多相关《微观计量经济学模型Model of MicroeconometricsWord文档下载推荐.docx(17页珍藏版)》请在冰点文库上搜索。
equalsthestandardnormalCDF
Inthelogitcase:
equalsthelogisticCDF
Example:
(1)Data
Consideringfemalelaborparticipationforasampleof872womenfromSwitzerland.
Thedependentvariable:
participation
Theexplainvariables:
income,age,education,youngkids,oldkids,foreignyesandage^2.
R:
library("
AER"
)
data("
SwissLabor"
summary(SwissLabor)
participationincomeageeducation
no:
471Min.:
7.187Min.:
2.000Min.:
1.000
yes:
4011stQu.:
10.4721stQu.:
3.2001stQu.:
8.000
Median:
10.643Median:
3.900Median:
9.000
Mean:
10.686Mean:
3.996Mean:
9.307
3rdQu.:
10.8873rdQu.:
4.8003rdQu.:
12.000
Max.:
12.376Max.:
6.200Max.:
21.000
youngkidsoldkidsforeign
Min.:
0.0000Min.:
0.0000no:
656
1stQu.:
0.00001stQu.:
0.0000yes:
216
0.0000Median:
1.0000
0.3119Mean:
0.9828
0.00003rdQu.:
2.0000
3.0000Max.:
6.0000
(2)Estimation
swiss_prob=glm(participation~.+I(age^2),data=SwissLabor,family=binomial(link="
probit"
))
summary(swiss_prob)
Call:
glm(formula=participation~.+I(age^2),family=binomial(link="
),
data=SwissLabor)
DevianceResiduals:
Min1QMedian3QMax
-1.9191-0.9695-0.47921.02092.4803
Coefficients:
EstimateStd.ErrorzvaluePr(>
|z|)
(Intercept)3.749091.406952.6650.00771**
income-0.666940.13196-5.0544.33e-07***
age2.075300.405445.1193.08e-07***
education0.019200.017931.0710.28428
youngkids-0.714490.10039-7.1171.10e-12***
oldkids-0.146980.05089-2.8880.00387**
foreignyes0.714370.121335.8883.92e-09***
I(age^2)-0.294340.04995-5.8933.79e-09***
---
Signif.codes:
0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1
(Dispersionparameterforbinomialfamilytakentobe1)
Nulldeviance:
1203.2on871degreesoffreedom
Residualdeviance:
1017.2on864degreesoffreedom
AIC:
1033.2
NumberofFisherScoringiterations:
4
(3)Visualization
Plottingparticipationversusage
plot(participation~age,data=SwissLabor,ylevels=2:
1)
(4)Effects
Averagemarginaleffects:
Theaverageofthesamplemarginaleffects:
fav=mean(dnorm(predict(swiss_prob,type="
link"
)))
fav*coef(swiss_prob)
(Intercept)incomeageeducationyoungkids
1.241929965-0.2209318580.6874661850.006358743-0.236682273
oldkidsforeignyesI(age^2)
-0.0486901700.236644422-0.097504844
Theaveragemarginaleffectsattheaverageregressor:
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="
av=dnorm(av)
av["
swiss"
]*coef(swiss_prob)[-7]
foreign"
swiss:
(Intercept)incomeageeducationyoungkids
1.495137092-0.2659758800.8276281450.007655177-0.284937521
oldkidsI(age^2)
-0.058617218-0.117384323
Foreign:
1.136517140-0.2021795510.6291152680.005819024-0.216593099
-0.044557434-0.089228804
(5)Goodnessoffitandprediction
Pseudo-R2:
asthelog-likelihoodforthefittedmodel,
asthelog-likelihoodforthemodelcontainingonlyaconstantterm.
swiss_prob0=update(swiss_prob,formula=.~1)
1-as.vector(logLik(swiss_prob)/logLik(swiss_prob0))
[1]0.1546416
Percentcorrectlypredicted:
table(true=SwissLabor$participation,pred=round(fitted(swiss_prob)))
pred
true01
no337134
yes146255
67.89%
ROCcurve:
TPR(c):
thenumberofwomenparticipatinginthelaborforcethatareclassifiedasparticipatingcomparedwiththetotalnumberofwomenparticipating.
FPR(c):
thenumberofwomennotparticipatinginthelaborforcethatareclassifiedasparticipatingcomparedwiththetotalnumberofwomennotparticipating.
ROCR"
pred=prediction(fitted(swiss_prob),SwissLabor$participation)
plot(performance(pred,"
acc"
tpr"
fpr"
abline(0,1,lty=2)
●Extensions:
Multinomialresponses
Forillustratingthemostbasicversionofthemultinomiallogitmodel,amodelwithonlyindividual-specificcovariates,.
BankWages"
Itcontains,foremployeesofaUSbank,anorderedfactorjobwithlevels"
custodial"
"
admin"
(foradministration),and"
manage"
(formanagement),tobemodeledasafunctionofeducation(inyears)andafactorminorityindicatingminoritystatus.Therealsoexistsafactorgender,butsincetherearenowomeninthecategory"
onlyasubsetofthedatacorrespondingtomalesisusedforparametricmodelingbelow.
summary(BankWages)
jobeducationgenderminority
custodial:
27Min.:
8.00male:
258no:
370
admin:
3631stQu.:
12.00female:
216yes:
104
manage:
84Median:
12.00
13.49
15.00
21.00
edcat<
-factor(BankWages$education)
edcat
levels(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)
nnet"
bank_mn2<
-multinom(job~education+minority+gender,
data=BankWages,trace=FALSE)
summary(bank_mn2)
1.3RegressionModelsforCountData
Webeginwiththestandardmodelforcountdata,aPoissonregression.
PoissonRegressionModel:
Canonicallink:
theloglink
TripstoLakeSomerville,Texas,1980.basedonasurveyadministeredto2,000registeredleisureboatownersin23countiesineasternTexas.Thedependentvariableistrips,andwewanttoregressitonallfurthervariables:
a(subjective)qualityrankingofthefacility(quality),afactorindicatingwhethertheindividualengagedinwater-skiingatthelake(ski),householdincome(income),afactorindicatingwhethertheindividualpaidauser’sfeeatthelake(userfee),andthreecostvariables(costC,costS,costH)representingopportunitycosts.
RecreationDemand"
summary(RecreationDemand)
tripsqualityskiincomeuserfee
0.000Min.:
0.000no:
417Min.:
1.000no:
646
0.0001stQu.:
0.000yes:
2421stQu.:
3.000yes:
13
0.000Median:
0.000Median:
3.000
2.244Mean:
1.419Mean:
3.853
2.0003rdQu.:
3.0003rdQu.:
5.000
88.000Max.:
5.000Max.:
9.000
costCcostScostH
4.34Min.:
4.767Min.:
5.70
28.241stQu.:
33.3121stQu.:
28.96
41.19Median:
47.000Median:
42.38
55.42Mean:
59.928Mean:
55.99
69.673rdQu.:
72.5733rdQu.:
68.56
493.77Max.:
491.547Max.:
491.05
head(RecreationDemand)
tripsqualityskiincomeuserfeecostCcostScostH
100yes4no67.5968.62076.800
200no9no68.8670.93684.780
300yes5no58.1259.46572.110
400no2no15.7913.75023.680
500yes3no24.0234.03334.547
600yes5no129.46137.377137.850
rd_pois=glm(trips~.,data=RecreationDemand,family=poisson)
coeftest(rd_pois)
ztestofcoefficients:
(Intercept)0.26499340.09372222.82740.004692**
quality0.47172590.017090527.6016<
2.2e-16***
skiyes0.41821370.05719027.31272.619e-13***
income-0.11132320.0195884-5.68311.323e-08***
userfeeyes0.89816530.078985111.3713<
costC-0.00342970.0031178-1.10010.271309
costS-0.04253640.0016703-25.4667<
costH0.03613360.002709613.3353<
0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘
logLik(rd_pois)
thelog-likelihoodofthefittedmodel:
'
logLik.'
-1529.431(df=8)
rbind(obs=table(RecreationDemand$trips)[1:
10],exp=round(
+sapply(0:
9,function(x)sum(dpois(x,fitted(rd_pois))))))
0123456789
obs417683834171311281
exp277146684130231713107
table(true=RecreationDemand$trips,pred=round(fitted(rd_nb)))
NOTWELL
(3)Dealingwithoverdispersion
Poissondistributionhasthepropertythatthevarianceequalsthemean.Ineconometrics,Poissonregressionsareoftenplaguedbyoverdispersion.
Onewayoftestingforoverdispersionistoconsiderthealternativehypothesis(CameronandTrivedi1990)
Var(yi|xi)=μi+a*h(μi)
wherehisapositivefunctionofμi.
Overdispersioncorrespondstoa>
0andunderdispersiontoa<
0.Commonspecificationsofthetransformationfunctionhareh(μ)=μ2orh(μ)=μ.Theformercorrespondstoanegativebinomial(NB)model(seebelow)withquadraticvariancefunction(calledNB2byCameronandTrivedi1998),thelattertoanNBmodelwithlinearvariancefunction(calledNB1byCameronandTrivedi1998).Inthestatisticalliterature,thereparameterization
Var(yi|xi)=(1+a)·
μi=dispersion·
μi
oftheNB1modelisoftencalledaquasi-Poissonmodelwithdispersionparameter.
dispersiontest(rd_pois)
Overdispersiontest
data:
rd_pois
z=2.4116,p-value=0.007941
alternativehypothesis:
truedispersionisgreaterthan1
sampleestimates:
dispersion
6.5658
dispersiontest(rd_pois,trafo=2)
Overdispersiontest
z=2.9381,p-value=0.001651
truealphaisgreaterthan0