From 2838b5c45d9a2992a5dd1fcbd12b41a54051c561 Mon Sep 17 00:00:00 2001 From: Ben Anderson <b.anderson@soton.ac.uk> Date: Fri, 6 Mar 2015 20:58:36 +0000 Subject: [PATCH] fixed error in sampling loop --- NEED/process-NEED-EULF-2014.do | 74 +++++++++++++++------------------- 1 file changed, 32 insertions(+), 42 deletions(-) diff --git a/NEED/process-NEED-EULF-2014.do b/NEED/process-NEED-EULF-2014.do index e835770..95c68b3 100644 --- a/NEED/process-NEED-EULF-2014.do +++ b/NEED/process-NEED-EULF-2014.do @@ -102,6 +102,7 @@ if `create_codebook' { log on main } + foreach s of local sample { local samplet "`s'pc" ***** random sample **** @@ -189,51 +190,40 @@ foreach s of local sample { if `create_longfile' { * create the long file with as few vars as possible (quicker) * still takes a while... - - keep HH_ID Gcons* Econs* - - * panel vars: - * Gcons2005 Gcons2005Valid Econs2005 Econs2005Valid -> 2012 - local vars "Gcons Econs" - foreach v of local vars { - di "* Renaming -> `v'" - foreach y of numlist 2005/2012 { - di "* -> `v' (`y')" - * put year on the end so reshape works - gen `v'Valid`y' = `v'`y'Valid - * remove old variable to save time in reshape & space - drop `v'`y'Valid - } - } - * this takes a LONG time for the full dataset - reshape long Gcons GconsValid Econs EconsValid, i(HH_ID) - rename _j year - * set as panel - xtset HH_ID year - compress - save "`dpath'/processed/`ifile'_consumptionfile_long_`samplet'.dta", replace + preserve + keep HH_ID Gcons* Econs* - log off main - log using "`dpath'/processed/codebook-NEED-EULF-2014-`ifile'-long-`version'-`sample'pc-$S_DATE.smcl", replace name(cbl) - desc - codebook - log close cbl - log on main - - * this leaves us with the long form file in memory + * panel vars: + * Gcons2005 Gcons2005Valid Econs2005 Econs2005Valid -> 2012 + local vars "Gcons Econs" + foreach v of local vars { + di "* Renaming -> `v'" + foreach y of numlist 2005/2012 { + di "* -> `v' (`y')" + * put year on the end so reshape works + gen `v'Valid`y' = `v'`y'Valid + * remove old variable to save time in reshape & space + drop `v'`y'Valid + } + } + * this takes a LONG time for the full dataset + reshape long Gcons GconsValid Econs EconsValid, i(HH_ID) + rename _j year + * set as panel + xtset HH_ID year + compress + save "`dpath'/processed/`ifile'_consumptionfile_long_`samplet'.dta", replace + + log off main + log using "`dpath'/processed/codebook-NEED-EULF-2014-`ifile'-long-`version'-`sample'pc-$S_DATE.smcl", replace name(cbl) + desc + codebook + log close cbl + log on main + restore + * this leaves us with the original file in memory } } -/* -* Link xwave data to long form file -* THIS TAKES AGES and creates a 1.5 GB file for the full dataset - use with care -* now just merge them -* start with long file which may or may not have just been re-created -use "`dpath'/`dfile'_consumptionfile_long.dta", clear - -merge m:1 HH_ID using "`dpath'/`dfile'_xwavefile.dta" - -save "`dpath'/`dfile'_consumptionfile_long_complete_`samplet'.dta", replace -*/ * done! -- GitLab