Skip to content
Snippets Groups Projects
Commit 2f320199 authored by Ben Anderson's avatar Ben Anderson
Browse files

fixed appending & summary graph

parent 1db7c8fe
No related branches found
No related tags found
No related merge requests found
...@@ -34,12 +34,16 @@ GNU General Public License for more details. ...@@ -34,12 +34,16 @@ GNU General Public License for more details.
global where "/Users/ben/Documents/Work" global where "/Users/ben/Documents/Work"
global proot "$where/Projects/ESRC-Transformative-Census2022" global proot "$where/Projects/ESRC-Transformative-Census2022"
global rpath "$proot/results/CER-Irish-SM-Trial"
* original files * original files
global odfiles "$where/Data/Social Science Datatsets/CER Smart Metering Project" global odfiles "$where/Data/Social Science Datatsets/CER Smart Metering Project"
* processed files * processed files
global pdfiles "$proot/data/cer" global pdfiles "$proot/data/cer/CER_OctHH_data"
* results path * results path
global rpath "$proot/results/CER-Irish-SM-Trial"
global version "v1" global version "v1"
...@@ -60,93 +64,90 @@ timer on 1 ...@@ -60,93 +64,90 @@ timer on 1
* see https://github.com/dataknut/Census2022/blob/master/CER-data-processing.do * see https://github.com/dataknut/Census2022/blob/master/CER-data-processing.do
* load 1/2 hour data (don't need survey for this) * load 1/2 hour data (don't need survey for this)
use "$pdfiles/CER_OctHH_data/CER_Oct2009HH_30min_survey.dta", clear use "$pdfiles/CER_Oct2009HH_30min_survey.dta", clear
local midweek "0 1" // 0 = weekends local midweek "0 1" // 0 = weekends
local midweekt1 "Mid-week" local midweekt1 "Midweek"
local midweekt0 "Weekends" local midweekt0 "Weekends"
* we have 36 values 'per day' (not 48)
* so lag 35 = this time tomorrow
* for mid-week, this time next week = lag 105
* for weekend, this time next week = lag 70
* so set max lags = 150 to cover both (will also mean 2 weekends)
local max_lag = 150
local midweektl0 xline(35 70, lstyle(refline ))
* the labels don't seem to show up?
local midweektll0 text(35 0.5 "This time tomorrow", place(w)) text(70 0.5 "This time next weekend", place(e)) // weekend
local midweektl0 xline(36 72, lstyle(refline )) local midweektl1 xline(35 70 105, lstyle(refline ))
local midweektll0 text(36 0 "This time tomorrow") text(72 0 "This time next weekend") // weekend * the labels don't seem to show up?
local midweektll1 text(35 0 "This time tomorrow", place(w)) text(70 0 "This time the day after tomorrow", place(w)) text(105 0 "This time next week", place(w)) // midweek
local midweektl1 xline(36 72 108, lstyle(refline ))
local midweektll1 text(36 0 "This time tomorrow") text(72 0 "This time the day after tomorrow") text(108 0 "This time next week") // midweek
* this creates a big list of all IDs so we can loop over it - takes a while
* could just start from min & loop to max - but would then be testing for non-existent households
qui: levelsof ID, local(ids)
local econt1 "In work" local econt1 "In work"
local econt2 "Unemployed" local econt2 "Unemployed"
local econt3 "Retired" local econt3 "Retired"
local econt4 "Caring for relative or family" local econt4 "Caring for relative or family"
* filter for
gen s_hour = hh(s_halfhour)
* this creates a big list of all IDs so we can loop over it - takes a while
* could just start from min & loop to max - but would then be testing for non-existent households
* qui: levelsof ID, local(ids)
* for testing
local ids "1002 1003 1004"
foreach m of local midweek { foreach m of local midweek {
di "****************" di "****************"
di "* Calculating ARs for midweek = `m'" di "* Calculating ARs for midweek = `m' (`midweekt`m'') "
foreach id of local ids { foreach id of local ids {
di "* -> ID = `id'" di "* -> ID = `id'"
preserve preserve
keep if ID == `id' & midweek == `m' & ds_halfhour >= 12 & ds_halfhour <= 48 // 06:00 - 24:00 -> 36 hour day * take out 00:00 - 06:00 as repeat cycle of sleep will swamp other cycles
* qui: su ds_halfhour keep if ID == `id' & midweek == `m' & s_hour > 6
* check * need to fool ac into thinking these observations are continuous
* di "Halfhours: `r(min)' - `r(max)'" qui: su ID
* skip over if fails due to lack of hubid qui: egen lag = fill(1(1)`r(N)')
capture noisily { tsset lag
* use s_datetime so ac knows what is missing * do this here so local is set to the unique valuye for this hh
qui: tsset s_datetime qui: levelsof ba_nchildren, local(nch)
* do this here so local is set to the unique valuye for this hh qui: levelsof ba_nadults, local(ba_nadults)
qui: levelsof ba_nchildren, local(nch) qui: levelsof ba_empl, local(econ)
qui: levelsof ba_nadults, local(ba_nadults) qui: su s_hour
qui: levelsof ba_empl, local(econ) di "Halfhours: `r(min)' - `r(max)' for ID: `id' (`midweekt`m'', N = `ba_nadults' adults, `nch' children, respondent: `econt`econ'')"
di "ID: `id' (`midweekt`m'', N = `ba_nadults' adults, `nch' children, respondent: `econt`econ'')" * this draws graph - slow
* we have 36 values 'per day' (not 48) qui: ac kwh, gen(archr) lags(`max_lag') name(ac_hubid`id'_`midweekt`m'') ///
* so lag 36 = this time tomorrow `midweektl`m'' /// draw lines
* for mid-week, this time next week = lag 108 `midweektll`m'' /// draw line labels
* for weekend, this time next week = lag 72 xlabel(0(35)140) ///
* so set max lags = 144 to cover both (will also mean 2 weekends) note("Halfhours: `r(min)' - `r(max)' for ID: `id' (`midweekt`m'', `ba_nadults' adult(s), `nch' children, respondent: `econt`econ'')")
* this draws graph - slow graph export "$rpath/graphs/kwh_archr_hubid`id'_`midweekt`m''_$version.png", replace
qui: ac kwh, gen(archr) lags(150) name(ac_hubid`id'_`midweekt`m'') ///
`midweektl`m''/// draw lines di "* save out arch results for household ID = `id'"
`midweektll`m'' /// draw line labels qui: keep lag archr ID
note("ID: `id' (`midweekt`m'', N = `ba_nadults' adults, `nch' children, respondent: `econt`econ'')") qui: save "$rpath/tmp/archr-`id'_`midweekt`m''_$version.dta", replace
graph export "$rpath/graphs/kwh_archr_hubid`id'_`midweekt`m''_$version.png", replace di "* Done"
di "* save out arch results for household ID = `id'"
qui: su t
qui: egen lag = fill(1(1)`r(max)')
qui: keep lag archr ID
qui: save "$rpath/tmp/archr-`id'_`midweekt`m''_$version.dta", replace
di "* Done"
}
restore restore
} }
} }
* reset the id loop values
qui: su ID
local id_min = `r(min)'
local id_max = `r(max)'
local id = `r(min)'
clear clear
* pool all the results * pool all the results
foreach m of local midweek { foreach m of local midweek {
di "****************" di "****************"
di "* Loading `midweekt`m'' files" di "* Loading `midweekt`m'' files"
while `id' < `id_max' { foreach id of local ids {
capture noisily { append using "$rpath/tmp/archr-`id'_`midweekt`m''_$version.dta"
append using "$rpath/tmp/archr-`id'_`midweekt`m''_$version.dta" erase "$rpath/tmp/archr-`id'_`midweekt`m''_$version.dta"
erase "$rpath/tmp/archr-`id'_`midweekt`m''_$version.dta"
}
* distribution of average values for first 70?
graph box archr if lag < 144, over(lag)
graph export "`rpath'/graphs/box_mean_archr_all_hubids_`midweekt`m''_`version'.png", replace
save "`rpath'/archr-all_hubids_`midweekt`m''_`version'.dta", replace
} }
* distribution of average values for first 70?
graph box archr if lag <= 105, over(lag)
graph export "$rpath/graphs/box_mean_archr_all_hubids_`midweekt`m''_$version.png", replace
save "$rpath/archr-all_hubids_`midweekt`m''_$version.dta", replace
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment