Download Econometric Analysis of Married Women's Labor Force Participation and more Study notes Econometrics and Mathematical Economics in PDF only on Docsity! MLE-1 TUTORIAL: MLE PROBIT. PRG: /* ** Probit MLE Estimation */ new ; @ LOADING DATA @ load dat[1962,25] = mwpsid82.db ; @ Data on married women from PSID @ @ OPEN OUTPUT FILE @ output file = probit.out reset ; @ DEFINE VARIABLES @ nlf = dat[.,1] ; @ dummy variable for non-labor-force @ emp = dat[.,2] ; @ dummy varrable for employed workers @ wrate = dat[.,3] ; @ hourly wage rate @ lrate = dat[.,4] ; @ log of (hourly wage rate ($)+1) @ edu = dat[.,5] ; @ years of schooling @ urb = dat[.,6] ; @ dummy variable for urban resident @ minor = dat[.,7] ; @ dummy variable for minority race @ age = dat[.,8] ; @ age @ tenure = dat[.,9] ; @ # of months under current employer @ expp = dat[.,10] ; @ years of experience since age 18 @ regs = dat[.,11] ; @ dummy variable for South @ occw = dat[.,12] ; @ dummy variable for white collar @ occb = dat[.,13] ; @ dummy variable for blue collar @ indumg = dat[.,14] ; @ dummy variable for manufacturing industry @ indumn = dat[.,15] ; @ dummy variable for non-manu. industry @ unionn = dat[.,16] ; @ dummy variable for union membership @ unempr = dat[.,17] ; @ local unemployment rate @ ofinc = dat[.,18] ; @ other family income in 1980 ($) @ lofinc = dat[.,19] ; @ log of (other family income + 1) @ kids = dat[.,20] ; @ # of children of age <= 17 @ MLE-2 wune80 = dat[.,21] ; @ UNKNOWN @ hwork = dat[.,22] ; @ hours of house work per week @ uspell = dat[.,23] ; @ # of unemployed weeks in 1980h @ search = dat[.,24] ; @ # of weeks looking for job in 1980 @ kids5 = dat[.,25] ; @ # of children of age <= 5 @ @ DEFINE # of OBSERVATIONS @ n = rows(dat) ; @ DEFINE DEPENDENT VARIABLE AND REGRESSORS @ @ Dependent variable @ yy = emp ; vny = {"emp"}; @ Regressors @ xx = ones(n,1)~edu~urb~minor~age~expp~kids~kids5~lofinc ; vnx = {"cons", "edu", "urb", "minor", "age", "expp", "kids", "kids5", "lofinc" }; /* ** DO NOT CHANGE FROM HERE */ @ DEFINE INITIAL VALUE @ bb = invpd(xx'xx)*(xx'yy) ; library optmum; #include optmum.ext; optset ; proc f(b) ; local ltt ; ltt = yy.*ln( cdfn(xx*b) ) + (1-yy).*ln( 1-cdfn(xx*b) ) ; RETP( -sumc(ltt) ) ; ENDP ; MLE-2 [OUTPUT] Probit Estimation Result ------------------------ dependent variable: emp log likelihood: -1167.9154 Pseudo R-square: 0.1390 LR test, df, p-val: 377.2165 8.0000 0.0000 Using Hessian variable coeff. std. err. t-st cons 2.2010 0.5087 4.3269 edu 0.0846 0.0153 5.5340 urb 0.1553 0.0667 2.3296 minor 0.0480 0.0671 0.7153 age -0.0344 0.0040 -8.6319 expp 0.0743 0.0059 12.6220 kids 0.0593 0.0264 2.2417 kids5 -0.5566 0.0513 -10.8400 lofinc -0.2595 0.0556 -4.6661 Using BHHH variable coeff. std. err. t-st cons 2.2010 0.5226 4.2115 edu 0.0846 0.0151 5.6031 urb 0.1553 0.0679 2.2886 minor 0.0480 0.0736 0.6522 age -0.0344 0.0041 -8.4538 expp 0.0743 0.0059 12.4907 kids 0.0593 0.0259 2.2850 kids5 -0.5566 0.0470 -11.8383 lofinc -0.2595 0.0566 -4.5859 Using Robust variable coeff. std. err. t-st cons 2.2010 0.4975 4.4237 edu 0.0846 0.0156 5.4338 urb 0.1553 0.0658 2.3591 minor 0.0480 0.0614 0.7811 age -0.0344 0.0039 -8.7092 expp 0.0743 0.0059 12.5926 kids 0.0593 0.0273 2.1742 kids5 -0.5566 0.0576 -9.6608 lofinc -0.2595 0.0548 -4.7324 MLE-3 TOBIT.PRG: /* ** Tobit MLE Estimation */ new ; @ LOADING DATA @ load dat[1962,25] = mwpsid82.db ; @ Data on married women from PSID 82 @ @ OPEN OUTPUT FILE @ output file = tobit.out reset ; @ DEFINE VARIABLES @ dat = delif(dat,dat[.,2] .== 0); @Delete nonemployed people@ nlf = dat[.,1] ; @ dummy variable for non-labor-force @ emp = dat[.,2] ; @ dummy varrable for employed workers @ wrate = dat[.,3] ; @ hourly wage rate @ lrate = dat[.,4] ; @ log of (hourly wage rate ($)+1) @ edu = dat[.,5] ; @ years of schooling @ urb = dat[.,6] ; @ dummy variable for urban resident @ minor = dat[.,7] ; @ dummy variable for minority race @ age = dat[.,8] ; @ age @ tenure = dat[.,9] ; @ # of months under current employer @ expp = dat[.,10] ; @ years of experience since age 18 @ regs = dat[.,11] ; @ dummy variable for South @ occw = dat[.,12] ; @ dummy variable for white collar @ occb = dat[.,13] ; @ dummy variable for blue collar @ indumg = dat[.,14] ; @ dummy var. for manufac. industry @ indumn = dat[.,15] ; @ dummy var. for non-manufac. industry @ unionn = dat[.,16] ; @ dummy variable for union membership @ unempr = dat[.,17] ; @ local unemployment rate @ ofinc = dat[.,18] ; @ other family income in 1980 ($) @ lofinc = dat[.,19] ; @ log of (other family income + 1) @ MLE-4 kids = dat[.,20] ; @ # of children of age <= 17 @ wune80 = dat[.,21] ; @ UNKNOWN @ hwork = dat[.,22] ; @ hours of house work per week @ uspell = dat[.,23] ; @ # of unemployed weeks in 1980 @ search = dat[.,24] ; @ # of weeks looking for job in 1980 @ kids5 = dat[.,25] ; @ # of children of age <= 5 @ @ DEFINE # of OBSERVATIONS @ n = rows(dat) ; @ DEFINE DEPENDENT VARIABLE AND REGRESSORS @ @ Dependent variable @ yy = uspell ; vny = {"uspell"}; @ Regressors @ xx = ones(n,1)~kids5~kids~edu~lofinc~age~expp~wrate~occw~occb ; vnx = {"cons", "kids5", "kids", "edu", "lofinc", "age", "expp", "wrate", "occw", "occb" }; /* ** DO NOT CHANGE FROM HERE */ @ DEFINE INITIAL VALUE @ bb = invpd(xx'xx)*(xx'yy) ; ss = sqrt((yy-xx*bb)'(yy-xx*bb)/n) ; bb = bb|ss ; @ dummy variable for yy @ v = 0 ; yd = dummy(yy,v); yd = yd[.,2] ; MLE-7 {b,func,grad,retcode} = optmum(&f,b0) ; @ value of likelihood function @ logl = -func ; @ Covariance matrix by Hessian @ covhess = invpd(hessi(b)) ; @ Covariance matrix by BHHH @ proc ff(b) ; local ltt, q; q = rows(b); ltt = yd.*( -.5*ln(2*pi) -.5*ln(b[q]^2) -(.5/b[q]^2).*(yy-xx*b[1:q-1])^2 ) + (1-yd).*ln( 1- cdfn( xx*b[1:q-1])/b[q] ) ; retp( ltt ) ; endp ; gtt = gradp(&ff,b); covbhhh = invpd(gtt'gtt) ; @ Robust covariance matrix @ covrob = covhess*invpd(covbhhh)*covhess ; @ Computing Standard errors @ sehess = sqrt(diag(covhess)); sebhhh = sqrt(diag(covbhhh)); serob = sqrt(diag(covrob)) ; stathess = b~sehess~(b./sehess); statbhhh = b~sebhhh~(b./sebhhh); MLE-8 statrob = b~serob~(b./serob); yyhess = vnx~stathess; yybhhh = vnx~statbhhh; yyrob = vnx~statrob; let mask[1,4] = 0 1 1 1; let fmt[4,3] = "-*.*s" 8 8 "*.*lf" 10 4 "*.*lf" 10 4 "*.*lf" 10 4; format /rd 10,4 ; "" ; "Tobit Estimation Result" ; "------------------------" ; " dependent variable: " $vny ; "" ; " log likelihood: " logl ; "" ; " Using Hessian "; "" ; "variable coeff. std. err. t-st " ; yyprin = printfm(yyhess,mask,fmt); " " ; " Using BHHH "; "" ; "variable coeff. std. err. t-st " ; yyprin = printfm(yybhhh,mask,fmt); "" ; " Using Robust "; "" ; "variable coeff. std. err. t-st " ; yyprin = printfm(yyrob,mask,fmt); output off ; MLE-9 [OUTPUT] Tobit Estimation Result ------------------------ dependent variable: uspell log likelihood: -933.4950 Using Hessian variable coeff. std. err. t-st cons -4.8340 22.3049 -0.2167 kids5 3.5827 2.4637 1.4542 kids -0.1792 1.2566 -0.1426 edu -0.2718 0.8127 -0.3345 lofinc 0.8886 2.2498 0.3950 age -0.5739 0.2198 -2.6107 expp -0.0550 0.3019 -0.1823 wrate -1.8647 0.6981 -2.6710 occw -2.1017 3.9879 -0.5270 occb 16.7014 4.4333 3.7672 sigma 28.0552 2.0858 13.4509 Using BHHH variable coeff. std. err. t-st cons -4.8340 31.1688 -0.1551 kids5 3.5827 2.6498 1.3521 kids -0.1792 1.4861 -0.1206 edu -0.2718 1.0740 -0.2531 lofinc 0.8886 3.1981 0.2779 age -0.5739 0.2621 -2.1895 expp -0.0550 0.3643 -0.1511 wrate -1.8647 0.5911 -3.1545 occw -2.1017 4.3457 -0.4836 occb 16.7014 5.9349 2.8141 sigma 28.0552 2.6810 10.4644 MLE-12 kids = dat[.,20] ; @ # of children of age <= 17 @ wune80 = dat[.,21] ; @ UNKNOWN @ hwork = dat[.,22] ; @ hours of house work per week @ uspell = dat[.,23] ; @ # of unemployed weeks in 1980 @ search = dat[.,24] ; @ # of weeks looking for job in 1980 @ kids5 = dat[.,25] ; @ # of children of age <= 5 @ @ DEFINE # of OBSERVATIONS @ n = rows(dat) ; @ DEFINE DEPENDENT VARIABLE AND REGRESSORS @ @ Dependent variable @ yy = uspell ; vny = {"uspell"}; @ Regressors @ xx = ones(n,1)~kids5~kids~edu~lofinc~age~expp~wrate~occw~occb ; vnx = {"cons", "kids5", "kids", "edu", "lofinc", "age", "expp", "wrate", "occw", "occb" }; /* ** DO NOT CHANGE FROM HERE */ vnx1 = {"sigma"}; vnx = vnx|vnx1 ; @ Deleting observations with y = 0 @ zz = yy~xx ; zz = delif(zz,zz[.,1] .== 0); yy = zz[.,1] ; xx = zz[.,2:cols(zz)]; @ DEFINE INITIAL VALUE @ MLE-13 bb = invpd(xx'xx)*(xx'yy) ; ss = sqrt((yy-xx*bb)'(yy-xx*bb)/n) ; bb = bb|ss ; library optmum; #include optmum.ext; optset ; proc f(b) ; local ltt, q ; q = rows(b); ltt = (-.5*ln(2*pi)-.5*ln(b[q]^2)-(.5/b[q]^2).*(yy-xx*b[1:q-1])^2 ) -ln( cdfn( xx*b[1:q-1]/abs(b[q]) ) ) ; retp( -sumc(ltt) ) ; endp ; b0 = bb ; __title = "Tobit MLE "; _opgtol = 1e-6; _opstmth = "bfgs,half"; __output = 1 ; {b,func,grad,retcode} = optmum(&f,b0) ; @ value of likelihood function @ logl = -func ; @ Covariance matrix by Hessian @ covhess = invpd(hessp(&f,b)) ; @ Covariance matrix by BHHH @ proc ff(b) ; local ltt, q; MLE-14 q = rows(b); ltt = (-.5*ln(2*pi)-.5*ln(b[q]^2)-(.5/b[q]^2).*(yy-xx*b[1:q-1])^2 ) - ln( cdfn( xx*b[1:q-1]/abs(b[q]) ) ) ; retp( ltt ) ; endp ; gtt = gradp(&ff,b); covbhhh = invpd(gtt'gtt) ; @ Robust covariance matrix @ covrob = covhess*invpd(covbhhh)*covhess ; @ Computing Standard errors @ sehess = sqrt(diag(covhess)); sebhhh = sqrt(diag(covbhhh)); serob = sqrt(diag(covrob)) ; stathess = b~sehess~(b./sehess); statbhhh = b~sebhhh~(b./sebhhh); statrob = b~serob~(b./serob); yyhess = vnx~stathess; yybhhh = vnx~statbhhh; yyrob = vnx~statrob; ::: MLE-17 HECKMAN1.PRG: /* ** Heckman's two-step estimation */ new ; @ LOADING DATA @ load dat[1962,25] = mwpsid82.db ; @ Data on married women from PSID 82 @ @ OPEN OUTPUT FILE @ output file = heckman1.out reset ; @ DEFINE VARIABLES @ nlf = dat[.,1] ; @ dummy variable for non-labor-force @ emp = dat[.,2] ; @ dummy varrable for employed workers @ wrate = dat[.,3] ; @ hourly wage rate @ lrate = dat[.,4] ; @ log of (hourly wage rate ($)+1) @ edu = dat[.,5] ; @ years of schooling @ urb = dat[.,6] ; @ dummy variable for urban resident @ minor = dat[.,7] ; @ dummy variable for minority race @ age = dat[.,8] ; @ age @ tenure = dat[.,9] ; @ # of months under current employer @ expp = dat[.,10] ; @ years of experience since age 18 @ regs = dat[.,11] ; @ dummy variable for South @ occw = dat[.,12] ; @ dummy variable for white collar @ occb = dat[.,13] ; @ dummy variable for blue collar @ indumg = dat[.,14] ; @ dummy variable for manufac. industry @ indumn = dat[.,15] ; @ dummy variable for non-manufac. industry @ unionn = dat[.,16] ; @ dummy variable for union membership @ unempr = dat[.,17] ; @ local unemployment rate @ ofinc = dat[.,18] ; @ other family income in 1980 ($) @ lofinc = dat[.,19] ; @ log of (other family income + 1) @ kids = dat[.,20] ; @ # of children of age <= 17 @ wune80 = dat[.,21] ; @ UNKNOWN @ hwork = dat[.,22] ; @ hours of house work per week @ uspell = dat[.,23] ; @ # of unemployed weeks in 1980 @ search = dat[.,24] ; @ # of weeks looking for job in 1980 @ kids5 = dat[.,25] ; @ # of children of age <= 5 @ @ DEFINE # of OBSERVATIONS @ n = rows(dat) ; @ DEFINE DEPENDENT VARIABLE AND REGRESSORS @ @ Dependent variable @ yy1 = lrate ; vny1 = {"lrate"} ; MLE-18 yy2 = emp ; vny2 = {"emp"} ; @ Regressors @ xx1 = ones(n,1)~edu~urb~minor~age~regs~unempr~expp~occw~occb; xx1 = xx1~unionn~tenure ; vnx1 = {"cons", "edu", "urb", "minor", "age", "regs", "unempr", "expp", "occw", "occb", "unionn", "tenure" }; xx2 = ones(n,1)~edu~urb~minor~age~regs~unempr~expp~lofinc~kids5 ; vnx2 = {"cons", "edu", "urb", "minor", "age", "regs", "unempr", "expp", "lofinc", "kids5" }; /* ** DO NOT CHANGE FROM HERE */ /* Begin the first Step */ @ DEFINE INITIAL VALUE @ bb = invpd(xx2'xx2)*(xx2'yy2) ; library optmum; #include optmum.ext; optset ; proc f(b) ; local ltt ; ltt = yy2.*ln( cdfn(xx2*b) ) + (1-yy2).*ln( 1-cdfn(xx2*b) ) ; RETP( -sumc(ltt) ) ; ENDP ; b0 = bb ; __title = "Heckman's Two-Step Estimator"; _opgtol = 1e-4; _opstmth = "bfgs, half"; __output = 0 ; {b,func,grad,retcode} = optmum(&f,b0) ; @ value of likelihood function @ logl = -func ; @ likelihood ratio test @ rlogl = sumc(yy2)*ln(sumc(yy2)/n) + (n-sumc(yy2))*ln(1-sumc(yy2)/n) ; lrt = 2*(logl-rlogl); lrdf = cols(xx2)-1 ; MLE-19 @ Covariance matrix by BHHH @ proc ff(b) ; local ltt ; ltt = yy2.*ln(cdfn(xx2*b)) + (1-yy2).*ln(1-cdfn(xx2*b)); RETP( ltt ) ; ENDP ; gtt = gradp(&ff,b); covbhhh = invpd(gtt'gtt) ; @ Computing Standard errors @ sebhhh = sqrt(diag(covbhhh)); statbhhh = b~sebhhh~(b./sebhhh); yybhhh = vnx2~statbhhh; ::: /* Begin the second Step */ @ Data selection @ yyy = yy2 ; zzz1 = yy1~xx1; zzz1 = delif(zzz1,yyy .== 0); yy1 = zzz1[.,1]; xx1 = zzz1[.,2:cols(zzz1)]; zzz2 = yy2~xx2; zzz2 = delif(zzz2,yyy .== 0); yy2 = zzz2[.,1]; xx2 = zzz2[.,2:cols(zzz2)]; @ Generating the selectivity regressor @ xb2 = xx2*b ; lam = pdfn(xb2)./cdfn(xb2) ; @ Define the list of regressors at the second step @ zz = xx1~lam ; @ OLS regression with the selectivity regressor @ gam = invpd(zz'zz)*(zz'yy1) ; sele = yy1 - zz*gam; rsq = 1 - (sele'sele)/( yy1'yy1 - rows(yy1)*meanc(yy1)^2 ) ; @ Residual from two-step @ vv = yy1 - zz*gam ; @ Calculating corrected variance of errors in eq. 1 @ @ Define sig12 = c @