// Øktri eksamen //1.1 tabstat LTV Age HouseholdSize, statistics(mean min max count) by (Moved) nototal columns(statistics) longstub twoway (histogram LTV, by(Moved, total cols(3) graphregion(color(white)))) //1.2 regress Moved LTV,r //1.3 predict Moved_est, xb hist Moved_est summarize Moved_est //2.1 gen Age2 = Age * Age regress Moved LTV HouseholdSize Age Age2, r //2.2 gen LTVo1 = 1 if LTV>1 replace LTVo1 = 0 if LTV < 1 gen LTVo1_LTV = LTVo1 * (LTV-1) regress Moved LTV HouseholdSize Age Age2 LTVo1 LTVo1_LTV, r //2.3 //3.1 ivregress 2sls Moved (LTV=LocalPriceChange) HouseholdSize Age Age2 LTVo1 LTVo1_LTV, r //3.2 //first stage ivregress 2sls Moved (LTV=LocalPriceChange) HouseholdSize Age Age2 LTVo1 LTVo1_LTV, r first //reduceret form regress Moved LocalPriceChange HouseholdSize Age Age2 LTVo1 LTVo1_LTV, r //3.3 gen HouseholdSize2=0 replace HouseholdSize2=1 if HouseholdSize==2 gen HouseholdSize2_LTV=HouseholdSize2*LTV gen HouseholdSize_inst=HouseholdSize2*LocalPriceChange ivregress 2sls Moved (LTV HouseholdSize2_LTV=LocalPriceChange HouseholdSize_inst) HouseholdSize Age Age2 LTVo1 LTVo1_LTV, r //5 MONTE CARLO clear all global numobs 500 set seed 38 program DGP, rclass drop _all set obs $numobs gen z = rnormal(0,1) gen u = rnormal(0,2) gen v = runiform(0,1) gen aA_0 = 1 gen aA_1 = $aA_1_global gen betaA_0 = 1 gen betaA_1 = 1 gen aB_0 = 1 gen aB_1 = 1 gen betaB_0 = 1 gen betaB_1 = 2 gen x = aA_0 + aA_1 * z + u if v>=0.5 replace x = aB_0 + aB_1 * z + u if v<0.5 gen y = betaA_0 + betaA_1 * x + u if v >= 0.5 replace y = betaB_0 + betaB_1 * x + u if v < 0.5 ivregress 2sls y (x=z) return scalar betaIV = _b[x] return scalar betase = _se[x] gen sumBeta = betaA_1 if v >= 0.5 replace sumBeta = betaB_1 if v < 0.5 sum sumBeta return scalar beta_mean = r(mean) regress y z //reduced form til at sammenligne return scalar beta_reduced=_b[z] end global aA_1_global 0 //5A simulate betaIV=r(betaIV) betase=r(betase), reps(1):DGP summarize //5B simulate betaIV=r(betaIV) betaMean=r(beta_mean) beta_reduced=r(beta_reduced), reps(1000):DGP summarize //5C global aA_1_global 1 simulate betaIV=r(betaIV) betaMean=r(beta_mean) beta_reduced=r(beta_reduced), reps(1000):DGP summarize