anonymous-submission-acl2025's picture
add 42
2a8276b
clear all
set more off
set maxvar 10000
set mem 500m
*Set path
***
*cd ---- specify path to \data_replication\psid\
local procdata "./proc_data/"
local rawdata "./raw_data/"
cd proc_data
*load income 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 //drop variables that are not useful
save pkX`x'.dta,replace
}
*Join datasets to form a panel
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 people that are inconsistent about their age (1/2/3 are consistent due to the differences in month of interview)
drop b
gen a=edu`x'-edu`i'
tab a
drop if a<0 // drop people that are inconsistent about their education (to adjust for any errors, see 2009 family codebook release info)
drop a
}
*Reshape the data for better use
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 ..
*###############################################################################
*Prepare the refinancing data for each year
*###############################################################################
forval x=2015(2)2017{
clear
*###############################################################################
*Prepare the wealth data
*###############################################################################
*Convert family files to stata format
cd raw_data
do FAM`x'ER.do
*Adjust wealth components
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
*###############################################################################
*Generate Panel and calculate Share of refinancing
*###############################################################################
use ref_temp_2015.dta, clear
forval x=2017(2)2017{
append using ref_temp_`x'.dta
}
sort hid year
xtset hid year
*sum up both mortgages
gen tot_mtg_debt=m1_principal+m2_principal
*generate difference in mortgage balances between survey waves
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 //make sure to account for people that had no mtg and got one (went from 0 to positive mtg balance)
*generate refinancing dummies
*1. any increase in mtg balance
gen refi_status1=1 if diff_mtg_balance>0 & diff_mtg_balance!=.
replace refi_status1=0 if refi_status1!=1
*2. 5% increase in mtg balance (results are the same in terms of nr of observations between option 1. and option 2.)
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
****************************************************************************************************************
*compute moments
****************************************************************************************************************
*create moments to be reported
gen liq_assets=(stocks+checking_savings-other_debt)/equiv
gen income = inc //already equivalized
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 age_head=age
gen mtg_payments_total = (mtg_paym1+mtg_paym2)/equiv
gen pti = mtg_payments_total/inc
*save file
save temp_refi_data.dta, replace
*************************************************************************
* OTHER REFI MOMENTS
*************************************************************************
*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*2017
*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
use temp_refi_data, clear
keep if year==2015 | year==2017
*move refi status one step behind
gen refit1=f2.refi_status2
gen refit2=f2.turnover1
gen refit=1 if refit1==1 & refit2!=1
replace refit=0 if refit!=1
*move back increase in mtg balance
gen mtg_delta=f2.pct_increase_mtg_balance
gen mtg_delta1=f2.diff_mtg_balance/house_val
*keep only orginal year
keep if year==2015
*winsorize data
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