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

create % samples of October 2009 data for teaching purposes

parent 51df1409
No related branches found
No related tags found
No related merge requests found
/*
**************************************************************
* Data preparation for ESRC Transformative project
* - Using the Commission for Energy Regulation (CER)'s Irish Smart Meter Trial data
* - http://www.ucd.ie/issda/data/commissionforenergyregulationcer/
* create working files of x % of the residential sample for teaching purposes
* This work was funded by RCUK through the ESRC's Transformative Social Science Programme via the
* "Census 2022: Transforming Small Area Socio-Economic Indicators through 'Big Data'" Project
* - http://gtr.rcuk.ac.uk/project/2D2CD798-4F04-4399-B1AF-D810A233DD21
* - http://www.energy.soton.ac.uk/tag/census2022/
Copyright (C) 2014 University of Southampton
Author: Ben Anderson (b.anderson@soton.ac.uk, @dataknut, https://github.com/dataknut)
[Energy & Climate Change, Faculty of Engineering & Environment, University of Southampton]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License
(http://choosealicense.com/licenses/gpl-2.0/), or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
#YMMV - http://en.wiktionary.org/wiki/YMMV
*/
global where "~/Documents/Work"
* project
global proot "$where/Data/CER Smart Metering Project"
* data
global dpath "$proot/data"
* log
global logpath "$proot/data/processed/logs"
global version "v1"
set more off
clear all
capture log close
log using "$logpath/CER-data-processing-samples-$version.smcl", replace
timer clear
timer on 1
************************************
************************************
* start with the sample allocations
use "$dpath/processed/SME and Residential allocations.dta"
* merge pre-trial residential survey data
merge 1:1 ID using "$dpath/processed/Smart meters Residential pre-trial survey data-$version.dta"
* keep the residential IDs only
keep if sample == 1
* keep basic info
keep ID sample res_stim res_tariff ba_*
* keep 10, 20 & 50% samples
local samples "10 20 50"
local infile = "$dpath/processed/CER-halfhour-electricity-Census2022-Oct-2009-sample"
foreach s of local samples {
preserve
di "* creating random sample of size `s' %"
* do this before we merge in the half hour data
sample `s'
desc, short
* merge the half-hour data
merge 1:m ID using "`infile'.dta"
* restrict to the matched households
keep if _merge == 3
* drop the spare stuff
drop residentialstimulusallocation_r residentialtariffallocation_r _merge ///
ba_sample m_ID_allocation m_alloc code kwh_mean kwh_sum residentialtariffallocation ///
residentialstimulusallocation smeallocation kwh_mean kwh_sum obs secs mins hours
desc, short
sort ID s_datetime
compress
save "`infile'_res_`s'pc_$version.dta", replace
outsheet using "`infile'_res_`s'pc_$version.csv", comma replace
restore
}
timer off 1
di "Time taken:"
timer list 1
log close
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment