From 891a31b2a89d441d4f2e1b84fac15fb6ead74d97 Mon Sep 17 00:00:00 2001 From: Liam Wright <45944168+ljwright@users.noreply.github.com> Date: Fri, 27 Nov 2026 11:11:11 +0000 Subject: [PATCH] Remove Stata do-files and link to the Stata site The Stata version of the guide now has its own website, so the Stata do-files and the "Download the equivalent Stata script" links are removed from this site. The introduction and README now link to the Stata site instead of saying that it will be developed. The download link was removed from the rendered pages directly as well as from the Quarto sources, so no pages were re-rendered. scripts/misc-extract_chunks.R no longer adds a Stata link to new pages. Co-Authored-By: Claude Fable 5.2 --- README.md | 2 +- do_files/bcs70-data_discovery.do | 42 ------- do_files/bcs70-merging_across_sweeps.do | 37 ------ do_files/bcs70-reshape_long_wide.do | 29 ----- do_files/mcs-data_discovery.do | 43 ------- do_files/mcs-household_grid.do | 44 -------- do_files/mcs-merging_across_sweeps.do | 98 ---------------- do_files/mcs-merging_within_sweep.do | 66 ----------- do_files/mcs-reshape_long_wide.do | 76 ------------- do_files/ncds-data_discovery.do | 43 ------- do_files/ncds-merging_across_sweeps.do | 37 ------ do_files/ncds-reshape_long_wide.do | 26 ----- do_files/next_steps-data_discovery.do | 44 -------- do_files/next_steps-data_structures.do | 16 --- do_files/next_steps-household_grid.do | 63 ----------- do_files/next_steps-merging_across_sweeps.do | 112 ------------------- do_files/next_steps-merging_within_sweep.do | 50 --------- do_files/next_steps-reshape_long_wide.do | 43 ------- docs/bcs70-data_discovery.md | 2 - docs/bcs70-merging_across_sweeps.md | 2 - docs/bcs70-reshape_long_wide.md | 2 - docs/intro.md | 2 +- docs/mcs-data_discovery.md | 2 - docs/mcs-household_grid.md | 2 - docs/mcs-merging_across_sweeps.md | 2 - docs/mcs-merging_within_sweep.md | 2 - docs/mcs-reshape_long_wide.md | 2 - docs/ncds-data_discovery.md | 2 - docs/ncds-merging_across_sweeps.md | 2 - docs/ncds-reshape_long_wide.md | 2 - docs/next_steps-data_discovery.md | 2 - docs/next_steps-data_structures.md | 2 - docs/next_steps-household_grid.md | 2 - docs/next_steps-merging_across_sweeps.md | 2 - docs/next_steps-merging_within_sweep.md | 2 - docs/next_steps-reshape_long_wide.md | 2 - quarto/bcs70-data_discovery.qmd | 1 - quarto/bcs70-merging_across_sweeps.qmd | 1 - quarto/bcs70-reshape_long_wide.qmd | 1 - quarto/mcs-data_discovery.qmd | 1 - quarto/mcs-household_grid.qmd | 1 - quarto/mcs-merging_across_sweeps.qmd | 1 - quarto/mcs-merging_within_sweep.qmd | 1 - quarto/mcs-reshape_long_wide.qmd | 1 - quarto/ncds-data_discovery.qmd | 1 - quarto/ncds-merging_across_sweeps.qmd | 1 - quarto/ncds-reshape_long_wide.qmd | 1 - quarto/next_steps-data_discovery.qmd | 1 - quarto/next_steps-data_structures.qmd | 1 - quarto/next_steps-household_grid.qmd | 1 - quarto/next_steps-merging_across_sweeps.qmd | 1 - quarto/next_steps-merging_within_sweep.qmd | 1 - quarto/next_steps-reshape_long_wide.qmd | 1 - scripts/misc-extract_chunks.R | 9 +- 54 files changed, 4 insertions(+), 929 deletions(-) delete mode 100644 do_files/bcs70-data_discovery.do delete mode 100644 do_files/bcs70-merging_across_sweeps.do delete mode 100644 do_files/bcs70-reshape_long_wide.do delete mode 100644 do_files/mcs-data_discovery.do delete mode 100644 do_files/mcs-household_grid.do delete mode 100644 do_files/mcs-merging_across_sweeps.do delete mode 100644 do_files/mcs-merging_within_sweep.do delete mode 100644 do_files/mcs-reshape_long_wide.do delete mode 100644 do_files/ncds-data_discovery.do delete mode 100644 do_files/ncds-merging_across_sweeps.do delete mode 100644 do_files/ncds-reshape_long_wide.do delete mode 100644 do_files/next_steps-data_discovery.do delete mode 100644 do_files/next_steps-data_structures.do delete mode 100644 do_files/next_steps-household_grid.do delete mode 100644 do_files/next_steps-merging_across_sweeps.do delete mode 100644 do_files/next_steps-merging_within_sweep.do delete mode 100644 do_files/next_steps-reshape_long_wide.do diff --git a/README.md b/README.md index 6bbba6a..694af63 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,6 @@ The Centre for Longitudinal Studies (CLS) manages four cohort studies for which 3. [Next Steps](https://doi.org/10.5334/ohd.16), a cohort of English schoolchildren followed from age 13/14 and born in 1989/90. 4. [The Millennium Cohort Study (MCS)](https://doi.org/10.1093/ije/dyu001), a birth cohort of individuals born in Britain in 2000/02. -This is the GitHub repository for the [cls-data.github.io](https://cls-data.github.io/) website which provides `R` and `Stata` code for common data management tasks in each of the studies. This include merging files across survey sweeps, reshaping data from wide to long format, and identifying correct identifier variables for observational units in each study (e.g., cohort members, families, parents, and so on). +This is the GitHub repository for the [cls-data.github.io](https://cls-data.github.io/) website which provides `R` code for common data management tasks in each of the studies. This include merging files across survey sweeps, reshaping data from wide to long format, and identifying correct identifier variables for observational units in each study (e.g., cohort members, families, parents, and so on). Equivalent `Stata` code is provided on a [separate website](https://cls-data.github.io/data-handling-stata) ([repository](https://github.com/CLS-Data/data-handling-stata)). For background on these studies, please see cohort profile papers (linked above) and the [CLS website](https://cls.ucl.ac.uk/cls-studies/). Queries on the data can be sent to the [CLS Data team](mailto:clsdata@ucl.ac.uk). \ No newline at end of file diff --git a/do_files/bcs70-data_discovery.do b/do_files/bcs70-data_discovery.do deleted file mode 100644 index 7563eaf..0000000 --- a/do_files/bcs70-data_discovery.do +++ /dev/null @@ -1,42 +0,0 @@ -* Load Packages -clear all -set more off - -* lookfor -use "38y/bcs8derived.dta", clear -lookfor "smok" "cigar" - -* codebook -log using codebook.log -codebook -log close - -* Create a Lookup Table Across All Datasets -* ssc install filelist -filelist, pattern("*.dta") -keep if !strmatch(dirname, "*UKDS*") -tempfile file_list -save `file_list' - -clear -tempfile all_vars -save `all_vars', emptyok - -use `file_list', clear -local n_files = _N -forvalues i = 1/`n_files' { - 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 -} - -use `all_vars', clear -gen name_low = lower(name) -gen varlab_low = lower(varlab) -list dir file name varlab if strmatch(varlab_low, "*smok*") | strmatch(varlab_low, "*cigar*") diff --git a/do_files/bcs70-merging_across_sweeps.do b/do_files/bcs70-merging_across_sweeps.do deleted file mode 100644 index 916174f..0000000 --- a/do_files/bcs70-merging_across_sweeps.do +++ /dev/null @@ -1,37 +0,0 @@ -clear all -set more off - -* Load 42y data -use BCSID BD9HGHTM using "42y/bcs70_2012_derived.dta", clear -rename *, lower -save "temp_42y.dta", replace - -* Load 51y data -use bcsid bd11hghtm using "51y/bcs11_age51_main.dta", clear -save "temp_51y.dta", replace - -* Full Join -use "temp_42y.dta", clear -merge 1:1 bcsid using "temp_51y.dta" -list * in 1/10 -// Use `drop _merge == x`to or run `merge ..., keep(x)` to keep a specific type of match/non-match. - -* Appending Sweeps -use "temp_42y.dta", clear -rename bd9* * -gen sweep = 9 -save "temp_42y_long.dta", replace - -use "temp_51y.dta", clear -rename bd11* * -gen sweep = 11 -save "temp_51y_long.dta", replace - -use "temp_42y_long.dta", clear -append using "temp_51y_long.dta" -sort bcsid sweep -list * in 1/10 - -* Adding Missing Rows -fillin bcsid sweep -list * in 1/10 diff --git a/do_files/bcs70-reshape_long_wide.do b/do_files/bcs70-reshape_long_wide.do deleted file mode 100644 index 2af0100..0000000 --- a/do_files/bcs70-reshape_long_wide.do +++ /dev/null @@ -1,29 +0,0 @@ -clear all -set more off - -* Load 42y data -use BCSID BD9HGHTM BD9WGHTK using "42y/bcs70_2012_derived.dta", clear -rename *, lower -save "temp_42y.dta", replace - -* Load 51y data -use bcsid bd11hghtm bd11wghtk using "51y/bcs11_age51_main.dta", clear -save "temp_51y.dta", replace - -* Merge -use "temp_42y.dta", clear -merge 1:1 bcsid using "temp_51y.dta" -keep if _merge == 3 // Keeps matches. `merge ..., keep(3)` would also work. -drop _merge - -* Rename -rename bd9* *9 -rename bd11* *11 - -* Reshape Long -reshape long hghtm wghtk, i(bcsid) j(sweep) -list * in 1/10 - -* Reshape Wide -reshape wide hghtm wghtk, i(bcsid) j(sweep) -list * in 1/10 diff --git a/do_files/mcs-data_discovery.do b/do_files/mcs-data_discovery.do deleted file mode 100644 index 1783414..0000000 --- a/do_files/mcs-data_discovery.do +++ /dev/null @@ -1,43 +0,0 @@ -* Load Packages -clear all -set more off - -* lookfor -use "17y/mcs7_cm_derived.dta", clear -lookfor "sdq" - - -* codebook -log using codebook.log -codebook -log close - -* Create a Lookup Table Across All Datasets -* ssc install filelist -filelist, pattern("*.dta") -keep if !strmatch(dirname, "*UKDS*") -tempfile file_list -save `file_list' - -clear -tempfile all_vars -save `all_vars', emptyok - -use `file_list', clear -local n_files = _N -forvalues i = 1/`n_files' { - 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 -} - -use `all_vars', clear -gen name_low = lower(name) -gen varlab_low = lower(varlab) -list dir file name varlab if strmatch(varlab_low, "*sdq*") diff --git a/do_files/mcs-household_grid.do b/do_files/mcs-household_grid.do deleted file mode 100644 index 0037971..0000000 --- a/do_files/mcs-household_grid.do +++ /dev/null @@ -1,44 +0,0 @@ -clear all -set more off - -* Finding Mother -use MCSID APNUM00 AHPSEX00 AHCREL00 using "0y/mcs1_hhgrid.dta", clear -label list AHPSEX00 AHCREL00 -numlabel AHPSEX00 AHCREL00, add // Alternatively tabulate -tabulate AHPSEX00 -tabulate AHCREL00 -keep if AHCREL00 == 7 & AHPSEX00 == 2 -bysort MCSID: gen n = _N -keep if n == 1 -drop n -keep MCSID APNUM00 -save "temp_mothers.dta", replace - -* Mother's Smoking -use MCSID APNUM00 APSMUS0A using "0y/mcs1_parent_interview.dta", clear -label list APSMUS0A -gen parent_smoker = . -replace parent_smoker = 1 if inrange(APSMUS0A, 2, 95) -replace parent_smoker = 0 if APSMUS0A == 1 -keep MCSID APNUM00 parent_smoker -save "temp_smoking.dta", replace - -* Merge -use "temp_mothers.dta", clear -merge 1:1 MCSID APNUM00 using "temp_smoking.dta", keep(master match) -drop _merge -rename parent_smoker mother_smoker -tabulate mother_smoker - -* Relationships -use MCSID APNUM00 AHPREL* using "0y/mcs1_hhgrid.dta", clear -list APNUM00 AHPRELA0 AHPRELB0 AHPRELC0 if MCSID == "M10001N" - -* Reshape for Partner -reshape long AHPREL, i(MCSID APNUM00) j(alt) string -gen alt_letter = substr(alt, 1, 1) -gen APNUM00_alt = (strpos("`c(ALPHA)'", alt_letter) + 1) / 2 // c(ALPHA) is inbuilt upper-case alphabet with spaces between letters -keep if AHPREL == 1 -keep MCSID APNUM00 APNUM00_alt -rename APNUM00_alt partner_pnum -list in 1/10 diff --git a/do_files/mcs-merging_across_sweeps.do b/do_files/mcs-merging_across_sweeps.do deleted file mode 100644 index e2ab0b5..0000000 --- a/do_files/mcs-merging_across_sweeps.do +++ /dev/null @@ -1,98 +0,0 @@ -clear all -set more off - -* Merging Across Sweeps -use MCSID BCNUM00 BCHTCM00 using "3y/mcs2_cm_interview.dta", clear -rename BCNUM00 CNUM00 -save "temp_3y.dta", replace - -use MCSID CCNUM00 CCHTCM00 using "5y/mcs3_cm_interview.dta", clear -rename CCNUM00 CNUM00 -save "temp_5y.dta", replace - -use "temp_3y.dta", clear -merge 1:1 MCSID CNUM00 using "temp_5y.dta" -list MCSID CNUM00 BCHTCM00 CCHTCM00 _merge in 1/10 - -* Appending Sweeps -use "temp_3y.dta", clear -rename B* * -gen sweep = 2 -save "temp_3y_long.dta", replace - -use "temp_5y.dta", clear -rename C* * -gen sweep = 3 -save "temp_5y_long.dta", replace - -use "temp_3y_long.dta", clear -append using "temp_5y_long.dta" -sort MCSID CNUM00 sweep -list MCSID CNUM00 sweep CHTCM00 in 1/10 - -* Programmatic Merging -global fups 0 3 5 7 11 14 17 - -capture program drop load_height_wide -program define load_height_wide, rclass - args sweep - - local stublist CNUM00 CHTCMA0 CHTCM00 - local prefix : word `sweep' of `c(ALPHA)' - local fup : word `sweep' of ${fups} - - local prefixed_list "" - foreach stubvar of local stublist { - local prefixed_list "`prefixed_list' `prefix'`stubvar'" - } - - describe using "`fup'y/mcs`sweep'_cm_interview.dta", varlist - local varlist `r(varlist)' - local in_file: list prefixed_list & varlist - - use MCSID `in_file' using "`fup'y/mcs`sweep'_cm_interview.dta", clear -end - -load_height_wide 3 -rename *CNUM00 CNUM00 - -tempfile next_merge -forvalues sweep = 4/7 { - preserve - load_height_wide `sweep' - rename *CNUM00 CNUM00 - save "`next_merge'", replace - restore - merge 1:1 MCSID CNUM00 using "`next_merge'", nogenerate -} - -sort MCSID CNUM00 -list * in 1/10 - - -* Programmatic Appending -capture program drop load_height_long -program define load_height_long, rclass - args sweep - - load_height_wide `sweep' - local prefix : word `sweep' of `c(ALPHA)' - rename `prefix'* * - rename CHTCM?0 CHTCM00 - local fup : word `sweep' of ${fups} - gen fup = `fup', after(CNUM00) -end - -load_height_long 3 - -tempfile next_append -forvalues sweep = 4/7 { - preserve - load_height_long `sweep' - save "`next_append'", replace - restore - append using "`next_append'" -} - -sort MCSID CNUM00 fup -list * in 1/10 diff --git a/do_files/mcs-merging_within_sweep.do b/do_files/mcs-merging_within_sweep.do deleted file mode 100644 index fb7a0f7..0000000 --- a/do_files/mcs-merging_within_sweep.do +++ /dev/null @@ -1,66 +0,0 @@ -clear all -set more off - -* Ethnicity -use MCSID BCNUM00 BDC08E00 using "3y/mcs2_cm_derived.dta", clear -rename BDC08E00 ethnic_group -save "df_ethnic_group.dta", replace - -* Country -use MCSID BACTRY00 using "3y/mcs2_family_derived.dta", clear -rename BACTRY00 country -save "df_country.dta", replace - -* Parent Reads -use MCSID BPNUM00 BCNUM00 BPOFRE00 using "3y/mcs2_parent_cm_interview.dta", clear -gen parent_reads = . -replace parent_reads = 1 if inrange(BPOFRE00, 1, 3) -replace parent_reads = 0 if inrange(BPOFRE00, 4, 6) -drop if missing(parent_reads) -collapse (max) parent_reads, by(MCSID BCNUM00) -save "df_reads.dta", replace - -* Warmth -use MCSID BCNUM00 BELIG00 BPPIAW00 using "3y/mcs2_parent_cm_interview.dta", clear -gen warmth = . -replace warmth = 0 if inrange(BPPIAW00, 1, 6) -replace warmth = 1 if BPPIAW00 == 5 -gen var_name = "main_warm" if BELIG00 == 1 -replace var_name = "secondary_warm" if BELIG00 != 1 -keep MCSID BCNUM00 var_name warmth -reshape wide warmth, i(MCSID BCNUM00) j(var_name) string -rename warmthmain_warm main_warm -rename warmthsecondary_warm secondary_warm -save "df_warm.dta", replace - -* NS-SEC -use MCSID BPNUM00 BDD05S00 using "3y/mcs2_parent_derived.dta", clear -rename BDD05S00 parent_nssec -replace parent_nssec = . if parent_nssec < 0 -drop if missing(parent_nssec) -collapse (min) family_nssec = parent_nssec, by(MCSID) -save "df_nssec.dta", replace - -* Mother Education -use MCSID BPNUM00 BHCREL00 BHPSEX00 using "3y/mcs2_hhgrid.dta", clear -keep if inrange(BPNUM00, 1, 99) & BHCREL00 == 7 & BHPSEX00 == 2 -duplicates drop MCSID BPNUM00, force -bysort MCSID: gen n = _N -keep if n == 1 -keep MCSID BPNUM00 -save "temp_mothers.dta", replace - -use MCSID BPNUM00 BDDNVQ00 using "3y/mcs2_parent_derived.dta", clear -rename BDDNVQ00 mother_nvq -merge 1:1 MCSID BPNUM00 using "temp_mothers.dta", keep(using match) -drop BPNUM00 -save "df_mother_edu.dta", replace - -* Merge All -use "df_ethnic_group.dta", clear -merge m:1 MCSID using "df_country.dta", keep(master match) nogenerate -merge m:1 MCSID using "df_nssec.dta", keep(master match) nogenerate -merge m:1 MCSID using "df_mother_edu.dta", keep(master match) nogenerate -merge 1:1 MCSID BCNUM00 using "df_reads.dta", keep(master match) nogenerate -merge 1:1 MCSID BCNUM00 using "df_warm.dta", keep(master match) nogenerate -list in 1/10 diff --git a/do_files/mcs-reshape_long_wide.do b/do_files/mcs-reshape_long_wide.do deleted file mode 100644 index d055209..0000000 --- a/do_files/mcs-reshape_long_wide.do +++ /dev/null @@ -1,76 +0,0 @@ -clear all -set more off - -* Reshape Raw Wide to Long -global fups 0 3 5 7 11 14 17 - -capture program drop load_anthro_wide -program define load_anthro_wide, rclass - args sweep - - local stublist CNUM00 CHTCMA0 CHTCM00 CWTCMA0 CWTCM00 - local prefix : word `sweep' of `c(ALPHA)' - local fup : word `sweep' of ${fups} - - local prefixed_list "" - foreach stubvar of local stublist { - local prefixed_list "`prefixed_list' `prefix'`stubvar'" - } - - describe using "`fup'y/mcs`sweep'_cm_interview.dta", varlist - local varlist `r(varlist)' - local in_file: list prefixed_list & varlist - - use MCSID `in_file' using "`fup'y/mcs`sweep'_cm_interview.dta", clear - rename *CNUM00 CNUM00 -end - -load_anthro_wide 1 - -tempfile next_merge -forvalues sweep = 2/7 { - preserve - load_anthro_wide `sweep' - save "`next_merge'", replace - restore - merge 1:1 MCSID CNUM00 using "`next_merge'", nogenerate -} - -rename ?C?TCMA0 ?C?TCM00 - -sort MCSID CNUM00 -list * in 1/10 - -** Reshape Raw Wide to Long -rename *CWTCM00 CWTCM00* -rename *CHTCM00 CHTCM00* -reshape long CWTCM00 CHTCM00, i(MCSID CNUM00) j(sweep_letter) string -list in 1/10 - -** Reshape Raw Long to Wide -reshape wide CHTCM00 CWTCM00, i(MCSID CNUM00) j(sweep_letter) string -rename CWTCM00* *CWTCM00 -rename CHTCM00* *CHTCM00 -list in 1/10 - - -* Cleaned Data -rename *CWTCM00 CWTCM00* -rename *CHTCM00 CHTCM00* -reshape long CHTCM00 CWTCM00, i(MCSID CNUM00) j(sweep_letter) string -gen sweep = (strpos("`c(ALPHA)'", sweep_letter) + 1) / 2 -gen fup = word("${fups}", sweep) -destring fup, replace - -gen height = CHTCM00 if CHTCM00 > 0 -gen weight = CWTCM00 if CWTCM00 > 0 -keep MCSID CNUM00 fup height weight -list in 1/10 - -* Reshape Clean Long to Wide -reshape wide height weight, i(MCSID CNUM00) j(fup) -list in 1/10 - -* Reshape Clean Wide to Long -reshape long height weight, i(MCSID CNUM00) j(fup) -list in 1/10 diff --git a/do_files/ncds-data_discovery.do b/do_files/ncds-data_discovery.do deleted file mode 100644 index 6ca411d..0000000 --- a/do_files/ncds-data_discovery.do +++ /dev/null @@ -1,43 +0,0 @@ -* Load Packages -clear all -set more off - -* lookfor -use "55y/ncds_2013_derived.dta", clear -lookfor "height" - - -* codebook -log using codebook.log -codebook -log close - -* Create a Lookup Table Across All Datasets -* ssc install filelist -filelist, pattern("*.dta") -keep if !strmatch(dirname, "*UKDS*") -tempfile file_list -save `file_list' - -clear -tempfile all_vars -save `all_vars', emptyok - -use `file_list', clear -local n_files = _N -forvalues i = 1/`n_files' { - 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 -} - -use `all_vars', clear -gen name_low = lower(name) -gen varlab_low = lower(varlab) -list dir file name varlab if strmatch(varlab_low, "*height*") diff --git a/do_files/ncds-merging_across_sweeps.do b/do_files/ncds-merging_across_sweeps.do deleted file mode 100644 index 23bede0..0000000 --- a/do_files/ncds-merging_across_sweeps.do +++ /dev/null @@ -1,37 +0,0 @@ -clear all -set more off - -* Load 23y data -use ncdsid dvwt23 using "23y/ncds4.dta", clear -rename *, upper -save "temp_23y.dta", replace - -* Load 50y data -use NCDSID DVWT50 using "50y/ncds_2008_followup.dta", clear -save "temp_50y.dta", replace - -* Full Join -use "temp_23y.dta", clear -merge 1:1 NCDSID using "temp_50y.dta" -list * in 1/10 -// Use `drop _merge == x`to or run `merge ..., keep(x)` to keep a specific type of match/non-match. - -* Appending Sweeps -use "temp_23y.dta", clear -rename DVWT23 DVWT -gen sweep = 23 -save "temp_23y_long.dta", replace - -use "temp_50y.dta", clear -rename DVWT50 DVWT -gen sweep = 50 -save "temp_50y_long.dta", replace - -use "temp_23y_long.dta", clear -append using "temp_50y_long.dta" -sort NCDSID sweep -list * in 1/10 - -* Add missing rows -fillin NCDSID sweep -list * in 1/10 diff --git a/do_files/ncds-reshape_long_wide.do b/do_files/ncds-reshape_long_wide.do deleted file mode 100644 index dff5d21..0000000 --- a/do_files/ncds-reshape_long_wide.do +++ /dev/null @@ -1,26 +0,0 @@ -clear all -set more off - -* Load 23y data -use ncdsid dvwt23 dvht23 using "23y/ncds4.dta", clear -rename *, upper -save "temp_23y.dta", replace - -* Load 50y data -use NCDSID DVWT50 DVHT50 using "50y/ncds_2008_followup.dta", clear -save "temp_50y.dta", replace - -* Merge -use "temp_23y.dta", clear -merge 1:1 NCDSID using "temp_50y.dta" -keep if _merge == 3 // Keeps matches. `merge ..., keep(3)` would also work. -drop _merge - -* Reshape Long -reshape long DVHT DVWT, i(NCDSID) j(fup) -list * in 1/10 - -* Reshape Wide -reshape wide DVHT DVWT, i(NCDSID) j(fup) -list * in 1/10 - diff --git a/do_files/next_steps-data_discovery.do b/do_files/next_steps-data_discovery.do deleted file mode 100644 index a55c6e2..0000000 --- a/do_files/next_steps-data_discovery.do +++ /dev/null @@ -1,44 +0,0 @@ -* Load Packages -clear all -set more off - -* lookfor -use "safeguarded_eul/ns8_2015_derived.dta", clear -lookfor "ghq" - -* codebook -log using codebook.log, replace -codebook -log close - -* Create a Lookup Table Across All Datasets -* ssc install filelist -filelist, pattern("*.dta") -keep if inlist(dirname, "./safeguarded_eul", "./household_grids", "./activity_histories") // Keeps files in the three Next Steps subfolders -tempfile file_list -save "`file_list'" - -clear -tempfile all_vars -save "`all_vars'", emptyok - -use "`file_list'", clear -local n_files = _N -forvalues i = 1/`n_files' { - 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 -} - -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 -list dir file sweep name varlab if strmatch(varlab_low, "*ghq*") -list dir file sweep name varlab if strmatch(varlab_low, "*ghq*") & strmatch(varlab_low, "*score*") diff --git a/do_files/next_steps-data_structures.do b/do_files/next_steps-data_structures.do deleted file mode 100644 index 4f4ebb8..0000000 --- a/do_files/next_steps-data_structures.do +++ /dev/null @@ -1,16 +0,0 @@ -clear all -set more off - -* Missing Values -capture program drop negative_to_na -program define negative_to_na - syntax varlist(numeric) - - 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 values of -1 or below with missing (.) -tabulate W1alceverYP, missing // Cleaned variable diff --git a/do_files/next_steps-household_grid.do b/do_files/next_steps-household_grid.do deleted file mode 100644 index 39b5462..0000000 --- a/do_files/next_steps-household_grid.do +++ /dev/null @@ -1,63 +0,0 @@ -clear all -set more off - -* Finding Mother -use NSID W1HhID W1Sex W1R_1 W1EmpStat using "household_grids/wave_one_lsype_household_grid_file_2020.dta", clear -numlabel, add // Adds numeric values to value labels -tabulate W1Sex -tabulate W1R_1 -keep if W1R_1 == 8 & W1Sex == 2 -bysort NSID: gen n = _N -keep if n == 1 -drop n -keep NSID W1HhID W1EmpStat - -* Mother's Employment -tabulate W1EmpStat -gen mother_works = . -replace mother_works = 1 if inrange(W1EmpStat, 1, 2) -replace mother_works = 0 if inrange(W1EmpStat, 3, 9) -keep NSID mother_works -tabulate mother_works, missing - -* Main and Second Parent -use NSID W1HhID W1Sex W1R_1 W1mainres W1secores using "household_grids/wave_one_lsype_household_grid_file_2020.dta", clear -gen role = "Main parent" if W1HhID == W1mainres -replace role = "Second parent" if W1HhID == W1secores & role == "" -drop if role == "" -bysort role: tabulate W1R_1 W1Sex - -* Changes in Main Parent Across Sweeps -use NSID W1HhID W1mainres using "household_grids/wave_one_lsype_household_grid_file_2020.dta", clear -keep if W1HhID == W1mainres -rename W1HhID w1_main_hhid -keep NSID w1_main_hhid -save "temp_w1_main.dta", replace - -use NSID W2HhID W2mainres using "household_grids/wave_two_lsype_household_grid_file_2020.dta", clear -keep if W2HhID == W2mainres -rename W2HhID w2_main_hhid -keep NSID w2_main_hhid - -merge 1:1 NSID using "temp_w1_main.dta", keep(match) nogenerate -gen same_person = w1_main_hhid == w2_main_hhid -tabulate same_person - -* Relationships -use NSID W1HhID W1R_* using "household_grids/wave_one_lsype_household_grid_file_2020.dta", clear -list W1HhID W1R_1 W1R_2 W1R_3 if NSID == NSID[1] - -* Reshape for Partner -reshape long W1R_, i(NSID W1HhID) j(W1HhID_alter) -keep if inlist(W1R_, 1, 2) -keep NSID W1HhID W1HhID_alter -rename W1HhID_alter partner_hhid -list in 1/10 // One row per couple: each relationship is only recorded for the person with the higher person number -save "temp_couples.dta", replace - -* Add Row for Other Partner -rename (W1HhID partner_hhid) (partner_hhid W1HhID) // Swaps the person numbers of the two partners -append using "temp_couples.dta" -order NSID W1HhID partner_hhid -sort NSID W1HhID -list in 1/10 diff --git a/do_files/next_steps-merging_across_sweeps.do b/do_files/next_steps-merging_across_sweeps.do deleted file mode 100644 index 4c9d23a..0000000 --- a/do_files/next_steps-merging_across_sweeps.do +++ /dev/null @@ -1,112 +0,0 @@ -clear all -set more off - -* Merging Across Sweeps -use NSID W2ghq12scr using "safeguarded_eul/wave_two_lsype_young_person_2020.dta", clear -save "temp_w2.dta", replace - -use NSID W4ghq12scr using "safeguarded_eul/wave_four_lsype_young_person_2020.dta", clear -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 `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 -rename W2* * -gen sweep = 2 -save "temp_w2_long.dta", replace - -use "temp_w4.dta", clear -rename W4* * -gen sweep = 4 -save "temp_w4_long.dta", replace - -use "temp_w2_long.dta", clear -append using "temp_w4_long.dta" -sort NSID sweep -list NSID sweep ghq12scr in 1/10 - -* Add Missing Rows -fillin NSID sweep -list * in 1/10 - -* Programmatic Merging -* Lookup lists: the nth word of each list gives the sweep, file and variable to use -global sweeps 2 4 8 9 -global files safeguarded_eul/wave_two_lsype_young_person_2020.dta safeguarded_eul/wave_four_lsype_young_person_2020.dta safeguarded_eul/ns8_2015_derived.dta safeguarded_eul/ns9_2022_derived_variables.dta -global ghq_vars W2ghq12scr W4ghq12scr W8DGHQSC W9DGHQSC - -capture program drop load_ghq_wide -program define load_ghq_wide - args i - - local file : word `i' of ${files} - local ghq_var : word `i' of ${ghq_vars} - - use NSID `ghq_var' using "`file'", clear -end - -load_ghq_wide 3 -list * in 1/10 - -load_ghq_wide 1 - -tempfile next_merge -forvalues i = 2/4 { - preserve - load_ghq_wide `i' - save "`next_merge'", replace - restore - merge 1:1 NSID using "`next_merge'", nogenerate -} - -sort NSID -list * in 1/10 -save "temp_ghq_wide.dta", replace - -* Programmatic Appending -capture program drop load_ghq_long -program define load_ghq_long - args i - - load_ghq_wide `i' - local ghq_var : word `i' of ${ghq_vars} - local sweep : word `i' of ${sweeps} - rename `ghq_var' ghq12 - label values ghq12 . // Removes value labels, which differ between sweeps - gen sweep = `sweep' -end - -load_ghq_long 1 - -tempfile next_append -forvalues i = 2/4 { - preserve - load_ghq_long `i' - save "`next_append'", replace - restore - append using "`next_append'" -} - -sort NSID sweep -list * in 1/10 - -* Replace Negative Values with Missing -capture program drop negative_to_na -program define negative_to_na - syntax varlist(numeric) - - recode `varlist' (min/-1 = .) -end - -negative_to_na ghq12 -list * in 1/10 - -* Defining the Sample with the Longitudinal File -use NSID MAINBOOST W?OUTCOME using "safeguarded_eul/ns9_2022_longitudinal_file.dta", clear -tabulate MAINBOOST -merge 1:1 NSID using "temp_ghq_wide.dta", keep(master match) nogenerate -list * in 1/10 diff --git a/do_files/next_steps-merging_within_sweep.do b/do_files/next_steps-merging_within_sweep.do deleted file mode 100644 index 0bad96d..0000000 --- a/do_files/next_steps-merging_within_sweep.do +++ /dev/null @@ -1,50 +0,0 @@ -clear all -set more off - -* Sex and Attitude to School -use NSID W1sexYP W1yschat1 using "safeguarded_eul/wave_one_lsype_young_person_2020.dta", clear -rename (W1sexYP W1yschat1) (sex school_attitude) -save "df_yp.dta", replace - -* Tenure -use NSID W1hous12HH using "safeguarded_eul/wave_one_lsype_family_background_2020.dta", clear -rename W1hous12HH tenure -save "df_tenure.dta", replace - -* Family NS-SEC -use NSID W1nssecMP W1nssecSP using "safeguarded_eul/wave_one_lsype_family_background_2020.dta", clear -replace W1nssecMP = . if !inrange(W1nssecMP, 1, 8) // Values outside 1-8 denote various forms of missingness -replace W1nssecSP = . if !inrange(W1nssecSP, 1, 8) -egen family_nssec = rowmin(W1nssecMP W1nssecSP) // Lowest value of the two variables in each row -keep NSID family_nssec -save "df_nssec.dta", replace - -* Mother's NS-SEC -use NSID W1mainres W1secores W1nssecMP W1nssecSP using "safeguarded_eul/wave_one_lsype_family_background_2020.dta", clear -rename (W1mainres W1secores) (W1HhIDMP W1HhIDSP) -reshape long W1HhID W1nssec, i(NSID) j(parent) string // One row per parent -save "temp_parent.dta", replace - -use NSID W1HhID W1Sex W1R_1 using "household_grids/wave_one_lsype_household_grid_file_2020.dta", clear -joinby NSID W1HhID using "temp_parent.dta" // Keeps matched rows only -keep if W1R_1 == 8 & W1Sex == 2 -bysort NSID: gen n = _N -keep if n == 1 -gen mother_nssec = W1nssec if inrange(W1nssec, 1, 8) -keep NSID mother_nssec -save "df_mother_nssec.dta", replace - -* Number of Siblings -use NSID W1HhID W1R_1 using "household_grids/wave_one_lsype_household_grid_file_2020.dta", clear -gen sibling = inrange(W1R_1, 13, 17) -collapse (sum) n_siblings = sibling, by(NSID) -save "df_siblings.dta", replace - -* Merge All -use "df_yp.dta", clear -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 diff --git a/do_files/next_steps-reshape_long_wide.do b/do_files/next_steps-reshape_long_wide.do deleted file mode 100644 index 251f994..0000000 --- a/do_files/next_steps-reshape_long_wide.do +++ /dev/null @@ -1,43 +0,0 @@ -clear all -set more off - -* Load and Merge -use NSID W8HEIGHT W8WEIGHT using "safeguarded_eul/ns8_2015_main_interview.dta", clear -save "temp_w8.dta", replace - -use NSID W9HEIGHT W9WEIGHT using "safeguarded_eul/ns9_2022_main_interview.dta", clear -merge 1:1 NSID using "temp_w8.dta", nogenerate -order NSID W8HEIGHT W8WEIGHT W9HEIGHT W9WEIGHT -sort NSID -list in 1/10 - -* Reshape Raw Wide to Long -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 - -* Reshape Raw Long to Wide -reshape wide HEIGHT WEIGHT, i(NSID) j(sweep) -rename (HEIGHT# WEIGHT#) (W#HEIGHT W#WEIGHT) -list in 1/10 - -* Cleaned Data -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 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 - -* Reshape Clean Long to Wide -reshape wide height weight, i(NSID) j(age) -rename (height# weight#) (height_# weight_#) -list in 1/10 - -* Reshape Clean Wide to Long -reshape long height_ weight_, i(NSID) j(age) -rename (height_ weight_) (height weight) -list in 1/10 diff --git a/docs/bcs70-data_discovery.md b/docs/bcs70-data_discovery.md index 2a73806..3c2ae58 100644 --- a/docs/bcs70-data_discovery.md +++ b/docs/bcs70-data_discovery.md @@ -10,8 +10,6 @@ format: - [Download the R script for this page](../purl/bcs70-data_discovery.R) -- [Download the equivalent Stata script for this - page](../do_files/bcs70-data_discovery.do) # Introduction diff --git a/docs/bcs70-merging_across_sweeps.md b/docs/bcs70-merging_across_sweeps.md index ba77cf0..1f0683e 100644 --- a/docs/bcs70-merging_across_sweeps.md +++ b/docs/bcs70-merging_across_sweeps.md @@ -11,8 +11,6 @@ format: - [Download the R script for this page](../purl/bcs70-merging_across_sweeps.R) -- [Download the equivalent Stata script for this - page](../do_files/bcs70-merging_across_sweeps.do) # Introduction diff --git a/docs/bcs70-reshape_long_wide.md b/docs/bcs70-reshape_long_wide.md index 9808384..999dedf 100644 --- a/docs/bcs70-reshape_long_wide.md +++ b/docs/bcs70-reshape_long_wide.md @@ -11,8 +11,6 @@ format: - [Download the R script for this page](../purl/bcs70-reshape_long_wide.R) -- [Download the equivalent Stata script for this - page](../do_files/bcs70-reshape_long_wide.do) # Introduction diff --git a/docs/intro.md b/docs/intro.md index 9fafcd9..0166980 100644 --- a/docs/intro.md +++ b/docs/intro.md @@ -13,7 +13,7 @@ The Centre for Longitudinal Studies (CLS) manages four cohort studies for which 3. [Next Steps](https://doi.org/10.5334/ohd.16), a cohort of English schoolchildren followed from age 13/14 and born in 1989/90. 4. [The Millennium Cohort Study (MCS)](https://doi.org/10.1093/ije/dyu001), a birth cohort of individuals born in Britain in 2000/02. -This website provides guided walkthroughs for using `R` for common data management tasks in each of the studies. This include merging files across survey sweeps, reshaping data from wide to long format, and using the correct variables to identify observational units (e.g., cohort members, families, parents, and so on). A separate website providing `Stata` walkthroughs will be developed in due course, though `Stata .do` files can be downloaded on each of the pages here. +This website provides guided walkthroughs for using `R` for common data management tasks in each of the studies. This include merging files across survey sweeps, reshaping data from wide to long format, and using the correct variables to identify observational units (e.g., cohort members, families, parents, and so on). Equivalent walkthroughs for `Stata` are available on a [separate website](https://cls-data.github.io/data-handling-stata). For background on CLS' studies, please see cohort profile papers (linked above) and the [CLS website](https://cls.ucl.ac.uk/cls-studies/). Queries about the data can be sent to the [CLS Data team](mailto:clsdata@ucl.ac.uk). Queries, comments and requests about this website can be directed to [Liam Wright](mailto:liam.wright@ucl.ac.uk) or raised as an issue on the [GitHub repository page](https://github.com/CLS-Data/CLS-Data.github.io). diff --git a/docs/mcs-data_discovery.md b/docs/mcs-data_discovery.md index 18273cd..cb5c33b 100644 --- a/docs/mcs-data_discovery.md +++ b/docs/mcs-data_discovery.md @@ -10,8 +10,6 @@ format: - [Download the R script for this page](../purl/mcs-data_discovery.R) -- [Download the equivalent Stata script for this - page](../do_files/mcs-data_discovery.do) # Introduction diff --git a/docs/mcs-household_grid.md b/docs/mcs-household_grid.md index f462270..29cfd8c 100644 --- a/docs/mcs-household_grid.md +++ b/docs/mcs-household_grid.md @@ -10,8 +10,6 @@ format: - [Download the R script for this page](../purl/mcs-household_grid.R) -- [Download the equivalent Stata script for this - page](../do_files/mcs-household_grid.do) # Introduction diff --git a/docs/mcs-merging_across_sweeps.md b/docs/mcs-merging_across_sweeps.md index efb25d3..7ff726e 100644 --- a/docs/mcs-merging_across_sweeps.md +++ b/docs/mcs-merging_across_sweeps.md @@ -11,8 +11,6 @@ format: - [Download the R script for this page](../purl/mcs-merging_across_sweeps.R) -- [Download the equivalent Stata script for this - page](../do_files/mcs-merging_across_sweeps.do) # Introduction diff --git a/docs/mcs-merging_within_sweep.md b/docs/mcs-merging_within_sweep.md index 5cf2907..e439240 100644 --- a/docs/mcs-merging_within_sweep.md +++ b/docs/mcs-merging_within_sweep.md @@ -11,8 +11,6 @@ format: - [Download the R script for this page](../purl/mcs-merging_within_sweep.R) -- [Download the equivalent Stata script for this - page](../do_files/mcs-merging_within_sweep.do) # Introduction diff --git a/docs/mcs-reshape_long_wide.md b/docs/mcs-reshape_long_wide.md index 6763e4d..15c637f 100644 --- a/docs/mcs-reshape_long_wide.md +++ b/docs/mcs-reshape_long_wide.md @@ -10,8 +10,6 @@ format: - [Download the R script for this page](../purl/mcs-reshape_long_wide.R) -- [Download the equivalent Stata script for this - page](../do_files/mcs-reshape_long_wide.do) # Introduction diff --git a/docs/ncds-data_discovery.md b/docs/ncds-data_discovery.md index 3d1db0f..7eb7a40 100644 --- a/docs/ncds-data_discovery.md +++ b/docs/ncds-data_discovery.md @@ -10,8 +10,6 @@ format: - [Download the R script for this page](../purl/ncds-data_discovery.R) -- [Download the equivalent Stata script for this - page](../do_files/ncds-data_discovery.do) # Introduction diff --git a/docs/ncds-merging_across_sweeps.md b/docs/ncds-merging_across_sweeps.md index c3e3a1f..bce44f3 100644 --- a/docs/ncds-merging_across_sweeps.md +++ b/docs/ncds-merging_across_sweeps.md @@ -11,8 +11,6 @@ format: - [Download the R script for this page](../purl/ncds-merging_across_sweeps.R) -- [Download the equivalent Stata script for this - page](../do_files/ncds-merging_across_sweeps.do) # Introduction diff --git a/docs/ncds-reshape_long_wide.md b/docs/ncds-reshape_long_wide.md index f26c04e..a704a2c 100644 --- a/docs/ncds-reshape_long_wide.md +++ b/docs/ncds-reshape_long_wide.md @@ -11,8 +11,6 @@ format: - [Download the R script for this page](../purl/ncds-reshape_long_wide.R) -- [Download the equivalent Stata script for this - page](../do_files/ncds-reshape_long_wide.do) # Introduction diff --git a/docs/next_steps-data_discovery.md b/docs/next_steps-data_discovery.md index 882ea88..d72a312 100644 --- a/docs/next_steps-data_discovery.md +++ b/docs/next_steps-data_discovery.md @@ -11,8 +11,6 @@ format: - [Download the R script for this page](../purl/next_steps-data_discovery.R) -- [Download the equivalent Stata script for this - page](../do_files/next_steps-data_discovery.do) # Introduction diff --git a/docs/next_steps-data_structures.md b/docs/next_steps-data_structures.md index 4297edf..bf5d090 100644 --- a/docs/next_steps-data_structures.md +++ b/docs/next_steps-data_structures.md @@ -11,8 +11,6 @@ format: - [Download the R script for this page](../purl/next_steps-data_structures.R) -- [Download the equivalent Stata script for this - page](../do_files/next_steps-data_structures.do) # Introduction diff --git a/docs/next_steps-household_grid.md b/docs/next_steps-household_grid.md index b4a7c0a..8cdc1c3 100644 --- a/docs/next_steps-household_grid.md +++ b/docs/next_steps-household_grid.md @@ -11,8 +11,6 @@ format: - [Download the R script for this page](../purl/next_steps-household_grid.R) -- [Download the equivalent Stata script for this - page](../do_files/next_steps-household_grid.do) # Introduction diff --git a/docs/next_steps-merging_across_sweeps.md b/docs/next_steps-merging_across_sweeps.md index e27fd7f..09c3ede 100644 --- a/docs/next_steps-merging_across_sweeps.md +++ b/docs/next_steps-merging_across_sweeps.md @@ -11,8 +11,6 @@ format: - [Download the R script for this page](../purl/next_steps-merging_across_sweeps.R) -- [Download the equivalent Stata script for this - page](../do_files/next_steps-merging_across_sweeps.do) # Introduction diff --git a/docs/next_steps-merging_within_sweep.md b/docs/next_steps-merging_within_sweep.md index 33e0970..25a3c55 100644 --- a/docs/next_steps-merging_within_sweep.md +++ b/docs/next_steps-merging_within_sweep.md @@ -11,8 +11,6 @@ format: - [Download the R script for this page](../purl/next_steps-merging_within_sweep.R) -- [Download the equivalent Stata script for this - page](../do_files/next_steps-merging_within_sweep.do) # Introduction diff --git a/docs/next_steps-reshape_long_wide.md b/docs/next_steps-reshape_long_wide.md index 3e8aeab..23d2ade 100644 --- a/docs/next_steps-reshape_long_wide.md +++ b/docs/next_steps-reshape_long_wide.md @@ -11,8 +11,6 @@ format: - [Download the R script for this page](../purl/next_steps-reshape_long_wide.R) -- [Download the equivalent Stata script for this - page](../do_files/next_steps-reshape_long_wide.do) # Introduction diff --git a/quarto/bcs70-data_discovery.qmd b/quarto/bcs70-data_discovery.qmd index a702ee7..8c2b0a2 100644 --- a/quarto/bcs70-data_discovery.qmd +++ b/quarto/bcs70-data_discovery.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/bcs70-data_discovery.R) -- [Download the equivalent Stata script for this page](../do_files/bcs70-data_discovery.do) # Introduction diff --git a/quarto/bcs70-merging_across_sweeps.qmd b/quarto/bcs70-merging_across_sweeps.qmd index 9858f21..41fdb3e 100644 --- a/quarto/bcs70-merging_across_sweeps.qmd +++ b/quarto/bcs70-merging_across_sweeps.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/bcs70-merging_across_sweeps.R) -- [Download the equivalent Stata script for this page](../do_files/bcs70-merging_across_sweeps.do) # Introduction diff --git a/quarto/bcs70-reshape_long_wide.qmd b/quarto/bcs70-reshape_long_wide.qmd index 207b8b3..daa8879 100644 --- a/quarto/bcs70-reshape_long_wide.qmd +++ b/quarto/bcs70-reshape_long_wide.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/bcs70-reshape_long_wide.R) -- [Download the equivalent Stata script for this page](../do_files/bcs70-reshape_long_wide.do) # Introduction diff --git a/quarto/mcs-data_discovery.qmd b/quarto/mcs-data_discovery.qmd index 337fe63..543e73c 100644 --- a/quarto/mcs-data_discovery.qmd +++ b/quarto/mcs-data_discovery.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/mcs-data_discovery.R) -- [Download the equivalent Stata script for this page](../do_files/mcs-data_discovery.do) # Introduction diff --git a/quarto/mcs-household_grid.qmd b/quarto/mcs-household_grid.qmd index f975cd5..0b7a0e6 100644 --- a/quarto/mcs-household_grid.qmd +++ b/quarto/mcs-household_grid.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/mcs-household_grid.R) -- [Download the equivalent Stata script for this page](../do_files/mcs-household_grid.do) # Introduction diff --git a/quarto/mcs-merging_across_sweeps.qmd b/quarto/mcs-merging_across_sweeps.qmd index 8a4b6ad..faacc00 100644 --- a/quarto/mcs-merging_across_sweeps.qmd +++ b/quarto/mcs-merging_across_sweeps.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/mcs-merging_across_sweeps.R) -- [Download the equivalent Stata script for this page](../do_files/mcs-merging_across_sweeps.do) # Introduction diff --git a/quarto/mcs-merging_within_sweep.qmd b/quarto/mcs-merging_within_sweep.qmd index a28de7a..c96bcdd 100644 --- a/quarto/mcs-merging_within_sweep.qmd +++ b/quarto/mcs-merging_within_sweep.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/mcs-merging_within_sweep.R) -- [Download the equivalent Stata script for this page](../do_files/mcs-merging_within_sweep.do) # Introduction diff --git a/quarto/mcs-reshape_long_wide.qmd b/quarto/mcs-reshape_long_wide.qmd index 7a27111..b042b84 100644 --- a/quarto/mcs-reshape_long_wide.qmd +++ b/quarto/mcs-reshape_long_wide.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/mcs-reshape_long_wide.R) -- [Download the equivalent Stata script for this page](../do_files/mcs-reshape_long_wide.do) # Introduction diff --git a/quarto/ncds-data_discovery.qmd b/quarto/ncds-data_discovery.qmd index ace9ed2..415d4be 100644 --- a/quarto/ncds-data_discovery.qmd +++ b/quarto/ncds-data_discovery.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/ncds-data_discovery.R) -- [Download the equivalent Stata script for this page](../do_files/ncds-data_discovery.do) # Introduction diff --git a/quarto/ncds-merging_across_sweeps.qmd b/quarto/ncds-merging_across_sweeps.qmd index d0b78cf..9946e9d 100644 --- a/quarto/ncds-merging_across_sweeps.qmd +++ b/quarto/ncds-merging_across_sweeps.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/ncds-merging_across_sweeps.R) -- [Download the equivalent Stata script for this page](../do_files/ncds-merging_across_sweeps.do) # Introduction diff --git a/quarto/ncds-reshape_long_wide.qmd b/quarto/ncds-reshape_long_wide.qmd index e09d754..62f3179 100644 --- a/quarto/ncds-reshape_long_wide.qmd +++ b/quarto/ncds-reshape_long_wide.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/ncds-reshape_long_wide.R) -- [Download the equivalent Stata script for this page](../do_files/ncds-reshape_long_wide.do) # Introduction diff --git a/quarto/next_steps-data_discovery.qmd b/quarto/next_steps-data_discovery.qmd index 8bd5051..0bcad71 100644 --- a/quarto/next_steps-data_discovery.qmd +++ b/quarto/next_steps-data_discovery.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/next_steps-data_discovery.R) -- [Download the equivalent Stata script for this page](../do_files/next_steps-data_discovery.do) # Introduction diff --git a/quarto/next_steps-data_structures.qmd b/quarto/next_steps-data_structures.qmd index a938437..4571943 100644 --- a/quarto/next_steps-data_structures.qmd +++ b/quarto/next_steps-data_structures.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/next_steps-data_structures.R) -- [Download the equivalent Stata script for this page](../do_files/next_steps-data_structures.do) # Introduction diff --git a/quarto/next_steps-household_grid.qmd b/quarto/next_steps-household_grid.qmd index 0f33f9b..59df43e 100644 --- a/quarto/next_steps-household_grid.qmd +++ b/quarto/next_steps-household_grid.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/next_steps-household_grid.R) -- [Download the equivalent Stata script for this page](../do_files/next_steps-household_grid.do) # Introduction diff --git a/quarto/next_steps-merging_across_sweeps.qmd b/quarto/next_steps-merging_across_sweeps.qmd index ab0e990..f3ae354 100644 --- a/quarto/next_steps-merging_across_sweeps.qmd +++ b/quarto/next_steps-merging_across_sweeps.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/next_steps-merging_across_sweeps.R) -- [Download the equivalent Stata script for this page](../do_files/next_steps-merging_across_sweeps.do) # Introduction diff --git a/quarto/next_steps-merging_within_sweep.qmd b/quarto/next_steps-merging_within_sweep.qmd index 6e6fcdd..10114ae 100644 --- a/quarto/next_steps-merging_within_sweep.qmd +++ b/quarto/next_steps-merging_within_sweep.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/next_steps-merging_within_sweep.R) -- [Download the equivalent Stata script for this page](../do_files/next_steps-merging_within_sweep.do) # Introduction diff --git a/quarto/next_steps-reshape_long_wide.qmd b/quarto/next_steps-reshape_long_wide.qmd index b5c9a5c..8c8085f 100644 --- a/quarto/next_steps-reshape_long_wide.qmd +++ b/quarto/next_steps-reshape_long_wide.qmd @@ -9,7 +9,6 @@ format: --- - [Download the R script for this page](../purl/next_steps-reshape_long_wide.R) -- [Download the equivalent Stata script for this page](../do_files/next_steps-reshape_long_wide.do) # Introduction diff --git a/scripts/misc-extract_chunks.R b/scripts/misc-extract_chunks.R index 2da8098..3563735 100644 --- a/scripts/misc-extract_chunks.R +++ b/scripts/misc-extract_chunks.R @@ -43,11 +43,7 @@ add_download_link <- function(quarto_file){ purl_file <- str_replace(quarto_file, "\\.qmd$", ".R") %>% file.path("purl", .) - do_file <- str_replace(quarto_file, "\\.qmd$", ".do") %>% - file.path("do_files", .) - download_links <- c(glue("- [Download the R script for this page](../{purl_file})"), - glue("- [Download the equivalent Stata script for this page](../{do_file})")) %>% - glue_collapse("\n") + download_links <- glue("- [Download the R script for this page](../{purl_file})") if (!any(str_detect(qmd, "Download the R script for this page"))){ qmd_download <- append(qmd, @@ -77,8 +73,7 @@ remove_download_link <- function(quarto_file){ if (any(str_detect(qmd, "Download the R script for this page"))){ qmd_remove <- tibble(line = qmd) %>% - filter(!str_detect(line, "Download the R script for this page"), - !str_detect(line, "Download the equivalent Stata script for this page")) %>% + filter(!str_detect(line, "Download the R script for this page")) %>% filter(!(line == "" & lead(line) == "")) %>% pull(line)