Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions do_files/next_steps-data_discovery.do
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ log close
* Create a Lookup Table Across All Datasets
* ssc install filelist
filelist, pattern("*.dta")
keep if !strmatch(dirname, "*UKDS*")
keep if inlist(dirname, "./safeguarded_eul", "./household_grids", "./activity_histories") // Keeps files in the three Next Steps subfolders
tempfile file_list
save `file_list'
save "`file_list'"

clear
tempfile all_vars
save `all_vars', emptyok
save "`all_vars'", emptyok

use `file_list', clear
use "`file_list'", clear
local n_files = _N
forvalues i = 1/`n_files' {
use `file_list' in `i', clear
use "`file_list'" in `i', clear
local filename = filename[1]
local dirname = dirname[1]
use "`dirname'/`filename'", clear
describe *, replace
gen dir = "`dirname'"
gen file = "`filename'"
append using `all_vars'
save `all_vars', replace
append using "`all_vars'"
save "`all_vars'", replace
}

use `all_vars', clear
use "`all_vars'", clear
gen name_low = lower(name)
gen varlab_low = lower(varlab)
gen sweep = real(regexs(1)) if regexm(name_low, "^w([0-9])") // Extracts sweep from the variable name
Expand Down
1 change: 0 additions & 1 deletion do_files/next_steps-household_grid.do
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ bysort NSID: gen n = _N
keep if n == 1
drop n
keep NSID W1HhID W1EmpStat
save "temp_mothers.dta", replace

* Mother's Employment
tabulate W1EmpStat
Expand Down
2 changes: 1 addition & 1 deletion do_files/next_steps-merging_across_sweeps.do
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ save "temp_w4.dta", replace
use "temp_w2.dta", clear
merge 1:1 NSID using "temp_w4.dta"
list NSID W2ghq12scr W4ghq12scr _merge in 1/10
// Use `drop if _merge == x` or run `merge ..., keep(x)` to keep a specific type of match/non-match.
// Use `keep if _merge == x` or run `merge ..., keep(x)` to keep a specific type of match/non-match.

* Appending Sweeps
use "temp_w2.dta", clear
Expand Down
6 changes: 3 additions & 3 deletions do_files/next_steps-reshape_long_wide.do
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sort NSID
list in 1/10

* Reshape Raw Wide to Long
rename (W#HEIGHT W#WEIGHT) (HEIGHT# WEIGHT#) // reshape requires the sweep number to be at the end of the name
rename (W#HEIGHT W#WEIGHT) (HEIGHT# WEIGHT#) // Moves the sweep number to the end of the name, where reshape expects it by default
reshape long HEIGHT WEIGHT, i(NSID) j(sweep)
list in 1/10

Expand All @@ -27,8 +27,8 @@ global ages 14 15 16 17 18 19 20 25 32
rename (W#HEIGHT W#WEIGHT) (HEIGHT# WEIGHT#)
reshape long HEIGHT WEIGHT, i(NSID) j(sweep)
gen age = real(word("${ages}", sweep))
gen height = HEIGHT if HEIGHT > 0
gen weight = WEIGHT if WEIGHT > 0
gen double height = HEIGHT if HEIGHT > 0 // double keeps the full precision of the raw values
gen double weight = WEIGHT if WEIGHT > 0
keep NSID age height weight
list in 1/10

Expand Down
Loading