/* Replication code: household assets and loneliness, Japan 2020-2024. Version: Stata 14.2. Put this file in the same directory as: loneliness_main_panel_anonymized.dta loneliness_ipw_baseline_anonymized.dta Do-file source: frozen November 7, 2026 paper specification. The anonymized person ID is common to both datasets. There are no original survey/record IDs in the shared datasets. Run this .do file from its containing folder (use "cd" first). Change RUN_LOO to 1 for all 4,165 leave-one-person-out regressions. */ version 14.2 clear all set more off capture log close _all log using "replication_stata_results.log", text replace tempfile main analysis_weights use "loneliness_main_panel_anonymized.dta", clear isid anon_id year xtset anon_id year assert _N==15105 egen byte person_tag=tag(anon_id) quietly count if person_tag assert r(N)==4165 gen double old_x_linc=old*linc gen double old_x_lasset=old*lasset forvalues yy=2021/2024 { gen byte old_year`yy'=old*(year==`yy') } local rhs "linc lasset old_x_linc old_x_lasset i.year old_year2021-old_year2024" save `main' display as result "=== PRIMARY TWO-WAY FIXED-EFFECTS ANALYSIS ===" xtreg ucla `rhs', fe vce(cluster anon_id) lincom lasset+old_x_lasset display as result "=== ASSET AND INCOME ORDINAL CATEGORIES ===" gen double old_x_inc=old*inc gen double old_x_asset=old*asset xtreg ucla inc asset old_x_inc old_x_asset i.year /// old_year2021-old_year2024, fe vce(cluster anon_id) display as result "=== TIME-VARYING WORK AND FAMILY CONTROLS ===" xtreg ucla `rhs' fulltime spouse alone, fe vce(cluster anon_id) display as result "=== ADDITIONAL HEALTH CONTROLS ===" xtreg ucla `rhs' fulltime spouse alone healthy depress, /// fe vce(cluster anon_id) display as result "=== SURVEY RETENTION RESTRICTION ===" preserve keep if retained2024==1 quietly count assert r(N)==9832 egen byte retained_tag=tag(anon_id) quietly count if retained_tag assert r(N)==2122 xtreg ucla `rhs', fe vce(cluster anon_id) bysort anon_id: gen byte nvalid=_N keep if nvalid==5 quietly count assert r(N)==8415 xtreg ucla `rhs', fe vce(cluster anon_id) restore display as result "=== INFLUENCE: 99TH PERCENTILE ASSET-SPAN TRIM ===" bysort anon_id: egen double min_asset=min(lasset) bysort anon_id: egen double max_asset=max(lasset) gen double asset_span=max_asset-min_asset _pctile asset_span if person_tag, p(99) local trim=r(r1) quietly count if person_tag & asset_span>`trim' assert r(N)==35 xtreg ucla `rhs' if asset_span<=`trim', fe vce(cluster anon_id) /* Set RUN_LOO=1 to reproduce the full leave-one-person-out range. */ local RUN_LOO=0 if `RUN_LOO' { preserve tempfile loo_results tempname loo_post postfile `loo_post' double beta using `loo_results', replace levelsof anon_id, local(persons) foreach who of local persons { quietly xtreg ucla `rhs' if anon_id!=`who', fe vce(cluster anon_id) post `loo_post' (_b[old_x_lasset]) } postclose `loo_post' use `loo_results', clear summarize beta display as result "LOO interaction coefficient min/max: " /// %9.7f r(min) " / " %9.7f r(max) restore } display as result "=== ALTERNATIVE BINARY OUTCOMES ===" xtreg bininc `rhs', fe vce(cluster anon_id) xtreg binstrict `rhs', fe vce(cluster anon_id) display as result "=== BASELINE-OBSERVABLE ATTRITION WEIGHTING ===" use "loneliness_ipw_baseline_anonymized.dta", clear isid anon_id assert _N==11384 quietly count if selected==1 assert r(N)==3867 assert age_sq==age_baseline^2 logit selected i.male c.age_baseline c.age_sq c.inc2020 /// c.asset2020 c.ucla2020 predict double p_selected if e(sample), pr gen double ipw=1/p_selected if selected==1 quietly summarize ipw if selected==1 replace ipw=ipw/r(mean) if !missing(ipw) keep anon_id ipw save `analysis_weights' use `main', clear merge m:1 anon_id using `analysis_weights', keep(match) nogen keep if !missing(ipw) assert _N==14287 display as result "=== SAME-SAMPLE UNWEIGHTED ===" xtreg ucla `rhs', fe vce(cluster anon_id) display as result "=== BASELINE IPW ===" xtreg ucla `rhs' [pw=ipw], fe vce(cluster anon_id) preserve egen byte one_per_person=tag(anon_id) _pctile ipw if one_per_person, p(95) local cap=r(r1) restore replace ipw=`cap' if ipw>`cap' & !missing(ipw) display as result "=== BASELINE IPW CAPPED AT 95TH PERCENTILE ===" xtreg ucla `rhs' [pw=ipw], fe vce(cluster anon_id) display as result "All replication analyses finished." log close