| clear all
|
| set more off
|
| set maxvar 10000
|
| set mem 500m
|
|
|
|
|
|
|
|
|
|
|
|
|
| local procdata "./proc_data/"
|
| local rawdata "./raw_data/"
|
|
|
| cd proc_data
|
|
|
|
|
| forval x=2015(2)2017{
|
| use pX`x'.dta, clear
|
| ren aftertax_income_defl_equiv inc`x'
|
| ren age_head age`x'
|
| ren ed_head edu`x'
|
| ren marital_status_head mstat`x'
|
| ren fam_ID_year fam_ID`x'
|
| ren size_fam size_fam`x'
|
| drop fam_ID_1968 year_survey year mstat
|
| save pkX`x'.dta,replace
|
| }
|
|
|
|
|
| use pkX2015.dta, clear
|
| forval x=2017(2)2017{
|
| joinby hid using pkX`x'.dta, unmatched(both)
|
| drop if _merge!=3
|
| drop _merge
|
| local i=`x'-2
|
| di "`i'"
|
| gen b=age`x'-age`i'
|
| tab b
|
| drop if b!=2 & b!=1 & b!=3
|
| drop b
|
| gen a=edu`x'-edu`i'
|
| tab a
|
| drop if a<0
|
| drop a
|
| }
|
|
|
|
|
| reshape long inc age edu mstat fam_ID size_fam, i(hid) j(year)
|
|
|
|
|
|
|
| drop if inc<0
|
|
|
|
|
| drop if year<2015
|
| drop if year>2017
|
| drop if age<25
|
| drop if age>85
|
|
|
| keep fam_ID year hid inc equiv age
|
| save income_panel1_temp.dta, replace
|
|
|
| cd ..
|
|
|
|
|
|
|
| forval x=2015(2)2017{
|
| clear
|
|
|
|
|
|
|
|
|
|
|
| cd raw_data
|
| do FAM`x'ER.do
|
|
|
|
|
| do wealth_comp`x'.do
|
| gen year=`x'
|
|
|
| drop ER*
|
|
|
| cd ..
|
| joinby fam_ID year using `procdata'income_panel1_temp.dta, unmatched(both)
|
| drop if _merge!=3
|
| drop _merge
|
|
|
| save `procdata'ref_temp_`x'.dta,replace
|
|
|
| }
|
|
|
| cd proc_data
|
|
|
|
|
|
|
|
|
|
|
| use ref_temp_2015.dta, clear
|
| forval x=2017(2)2017{
|
| append using ref_temp_`x'.dta
|
| }
|
|
|
| sort hid year
|
| xtset hid year
|
|
|
|
|
| gen tot_mtg_debt=m1_principal+m2_principal
|
|
|
|
|
| gen past_mtg_balance=L2.tot_mtg_debt
|
| gen diff_mtg_balance=tot_mtg_debt-past_mtg_balance
|
| replace diff_mtg_balance=. if past_mtg_balance==0
|
|
|
|
|
|
|
| gen refi_status1=1 if diff_mtg_balance>0 & diff_mtg_balance!=.
|
| replace refi_status1=0 if refi_status1!=1
|
|
|
| gen pct_increase_mtg_balance=diff_mtg_balance/past_mtg_balance
|
| gen refi_status2=1 if diff_mtg_balance>=.05 & diff_mtg_balance!=.
|
| replace refi_status2=0 if refi_status2!=1
|
|
|
|
|
|
|
|
|
|
|
| gen liq_assets=(stocks+checking_savings-other_debt)/equiv
|
| gen income = inc
|
| gen liq_assets_to_inc = liq_assets/income
|
| gen h_net_worth_share = (house_val - m1_principal-m2_principal)/wealth
|
| gen wlth = wealth/equiv
|
| gen ltv_m=tot_mtg_debt/house_val
|
| gen h_value=house_val/equiv
|
|
|
| gen mtg_payments_total = (mtg_paym1+mtg_paym2)/equiv
|
| gen pti = mtg_payments_total/inc
|
|
|
| save temp_refi_data.dta, replace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| use temp_refi_data, clear
|
| keep if year==2015 | year==2017
|
|
|
| gen refit1=f2.refi_status2
|
| gen refit2=f2.turnover1
|
| gen refit=1 if refit1==1 & refit2!=1
|
| replace refit=0 if refit!=1
|
|
|
| gen mtg_delta=f2.pct_increase_mtg_balance
|
| gen mtg_delta1=f2.diff_mtg_balance/house_val
|
|
|
| keep if year==2015
|
|
|
| winsor2 liq_assets income liq_assets_to_inc h_net_worth_share wlth ltv_m h_value age_head pti mtg_delta mtg_delta1, replace cuts(1 99)
|
|
|
|
|
| preserve
|
| collapse (mean) refit
|
| gen res=round(refit, 0.01)/2
|
| replace res=round(res, 0.01)
|
| gen title="fraction of people refinance"
|
| save moment1.dta, replace
|
| restore
|
|
|
|
|
| forval x=1(1)1{
|
| use moment`x'.dta, clear
|
| keep res title
|
| duplicates drop
|
| save moment`x'.dta, replace
|
| }
|
|
|
| use moment1.dta, clear
|
|
|
| order title res
|
|
|
| cd ..
|
|
|
| cd output
|
|
|
| outsheet using tabA3_refi.csv, replace c
|
|
|
|
|
|
|