From 0f14bcafcf26bfbeac7889f07df3a5659c73b2a5 Mon Sep 17 00:00:00 2001 From: Liam Wright <45944168+ljwright@users.noreply.github.com> Date: Fri, 27 Nov 2026 10:30:51 +0000 Subject: [PATCH] Update three Next Steps Stata do-files - Data structures and combining data across sweeps: negative_to_na now uses recode (values of -1 or below become missing) in place of a loop over the variables. - Combining data within a sweep: set linesize 255 before the final listing, so that each row is printed on one line. Co-Authored-By: Claude Fable 5.2 --- do_files/next_steps-data_structures.do | 6 ++---- do_files/next_steps-merging_across_sweeps.do | 4 +--- do_files/next_steps-merging_within_sweep.do | 1 + 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/do_files/next_steps-data_structures.do b/do_files/next_steps-data_structures.do index 0f01cfd..4f4ebb8 100644 --- a/do_files/next_steps-data_structures.do +++ b/do_files/next_steps-data_structures.do @@ -6,13 +6,11 @@ capture program drop negative_to_na program define negative_to_na syntax varlist(numeric) - foreach var of varlist `varlist' { - replace `var' = . if `var' < 0 - } + recode `varlist' (min/-1 = .) end use NSID W1alceverYP using "safeguarded_eul/wave_one_lsype_young_person_2020.dta", clear numlabel, add // Adds numeric values to value labels tabulate W1alceverYP, missing // Raw variable -negative_to_na W1alceverYP // Replaces negative values with missing (.) +negative_to_na W1alceverYP // Replaces values of -1 or below with missing (.) tabulate W1alceverYP, missing // Cleaned variable diff --git a/do_files/next_steps-merging_across_sweeps.do b/do_files/next_steps-merging_across_sweeps.do index 4f49c84..4c9d23a 100644 --- a/do_files/next_steps-merging_across_sweeps.do +++ b/do_files/next_steps-merging_across_sweeps.do @@ -99,9 +99,7 @@ capture program drop negative_to_na program define negative_to_na syntax varlist(numeric) - foreach var of varlist `varlist' { - replace `var' = . if `var' < 0 - } + recode `varlist' (min/-1 = .) end negative_to_na ghq12 diff --git a/do_files/next_steps-merging_within_sweep.do b/do_files/next_steps-merging_within_sweep.do index 8f5f7d4..0bad96d 100644 --- a/do_files/next_steps-merging_within_sweep.do +++ b/do_files/next_steps-merging_within_sweep.do @@ -46,4 +46,5 @@ merge 1:1 NSID using "df_tenure.dta", keep(master match) nogenerate merge 1:1 NSID using "df_nssec.dta", keep(master match) nogenerate merge 1:1 NSID using "df_mother_nssec.dta", keep(master match) nogenerate merge 1:1 NSID using "df_siblings.dta", keep(master match) nogenerate +set linesize 255 // Widens the output so that each row of the listing fits on one line list in 1/10