clear
#delimit ;
set mem 5m;
set matsize 800;
set more off;
local daysindec = 31;
local minsinhr = 60;
local hrsinday = 24;
insheet using fundraiser2005q4clean.txt, names;
drop if time=="";
replace time = substr(time,1,8);
gen hour = real(substr(time,1,2));
gen minute = real(substr(time,4,2));
gen second = real(substr(time,7,2));
gen amt = real(regexr(gross,",",""));
gen d = date(date,"ymd");
gen yr = year(d);
gen mo = month(d);
gen day = day(d);
gen dow = dow(d); /* 0 is Sunday; 6 is Saturday */
label define daysofweek 6 "Saturday" 0 "Sunday" 1 "Monday" 2 "Tuesday" 3 "Wednesday" 4 "Thursday" 5 "Friday";
label var dow "Day of the Week";
label values dow daysofweek;
quietly summ day; local day0 = r(min);
quietly summ dow if day==`day0'; local dowday0 = r(min);
gen week = 1 + floor((day+`daysindec'*(mo==1)-`day0'+`dowday0')/7);
save fundraiser2005q4.dta, replace;
/* Preliminary analysis:
bys currency: summ amt;
hist amt if currency=="EUR";
hist amt if (currency=="EUR")&(amt<200);
bys day: summ amt if curr=="USD";
*/
/*exit;*/
/* For obtaining plots of contributions over time: */
sort yr mo day currency;
collapse (mean) dow=dow week=week avgamt=amt (sum) total=amt (count) ndonations=amt (sd) sdamt=amt, by(yr mo day currency);
/* scatter total day if curr=="USD";
line total day if curr=="USD"; */
sort week;
twoway (connected total dow if week==1)
(connected total dow if week==2)
(connected total dow if week==3)
(connected total dow if week==4)
if curr=="USD",
title("Total USD Donations by Day and by Week")
ytitle("Dollars")
ysca(titlegap(*3))
ysc(r(0))
ylabel(#6)
xtitle("Day")
xlabel(5 "Friday" 6 "Saturday" 0 "Sunday" 1 "Monday" 2 "Tuesday" 3 "Wednesday" 4 "Thursday")
legend(label(1 "12/16/2005-12/17/2005")
label(2 "12/18/2005-12/24/2005")
label(3 "12/25/2005-12/31/2005")
label(4 "1/1/2006-1/6/2006"))
caption("This figure plots total USD-denominated contributions received, by day and by week "
"of the 2005q4 fundraising drive.");
graph export contribsbyday2005q4.png, replace;
twoway (connected ndon dow if week==1)
(connected ndon dow if week==2)
(connected ndon dow if week==3)
(connected ndon dow if week==4)
if curr=="USD",
title("Number of USD Donations by Day and by Week")
ytitle("USD Donations")
ysca(titlegap(*3))
ysc(r(0))
ylabel(#6)
xtitle("Day")
xlabel(5 "Friday" 6 "Saturday" 0 "Sunday" 1 "Monday" 2 "Tuesday" 3 "Wednesday" 4 "Thursday")
legend(label(1 "12/16/2005-12/17/2005")
label(2 "12/18/2005-12/24/2005")
label(3 "12/25/2005-12/31/2005")
label(4 "1/1/2006-1/6/2006"))
caption("This figure plots total USD-denominated contributions received, by day and by week "
"of the 2005q4 fundraising drive.");
graph export ndonationsbyday2005q4.png, replace;
twoway (connected avgamt dow if week==1)
(connected avgamt dow if week==2)
(connected avgamt dow if week==3)
(connected avgamt dow if week==4)
if curr=="USD",
title("Average Size of USD Donations by Day and by Week")
ytitle("Dollars")
ysca(titlegap(*3))
ysc(r(0))
ylabel(#6)
xtitle("Day")
xlabel(5 "Friday" 6 "Saturday" 0 "Sunday" 1 "Monday" 2 "Tuesday" 3 "Wednesday" 4 "Thursday")
legend(label(1 "12/16/2005-12/17/2005")
label(2 "12/18/2005-12/24/2005")
label(3 "12/25/2005-12/31/2005")
label(4 "1/1/2006-1/6/2006"))
caption("This figure plots total USD-denominated contributions received, by day and by week "
"of the 2005q4 fundraising drive.");
graph export avgsizebyday2005q4.png, replace;
/**/
exit;
use fundraiser2005q4.dta;
gen mins_since_start = (day-`day0')*`hrsinday'*`minsinhr' + hour*`minsinhr' + minute;
/* The pictures on the banner were up from 00:15 UTC until 01:30 UTC on December 28. */
local bannert0 = (28-`day0')*`hrsinday'*`minsinhr' + 15;
local bannert1 = (28-`day0')*`hrsinday'*`minsinhr' + 90;
local bannerdur = `bannert1' - `bannert0';
gen bannerpix = (mins_since_start >= `bannert0') & (mins_since_start <= `bannert1');
local controlt0 = (21-`day0')*`hrsinday'*`minsinhr' + 15;
local controlt1 = (21-`day0')*`hrsinday'*`minsinhr' + 90;
/*
bys curr: regress amt bannerpix;
bys bannerpix: summ amt if curr=="USD", d;
*/
macro list;
/*
gen timepd = floor((mins_-`bannert0')/(`bannert1'-`bannert0')) * (`bannert1'-`bannert0');
egen ndow = group(dow);
sort timepd curr;
collapse (sum) total=amt (count) ndonations=amt (sd) sdamt=amt, by(timepd curr);
*/
gen bp = 1*((mins_<`controlt0')&(mins>=`controlt0'-`bannerdur'))
+ 2*((mins_>=`controlt0')&(mins<=`controlt1'))
+ 3*((mins_>`controlt1')&(mins<=`controlt1'+`bannerdur'))
+ 4*((mins_since_start < `bannert0') & (mins_since_start >= `bannert0' - `bannerdur'))
+ 5*bannerpix
+ 6*((mins_since_start > `bannert1') & (mins_since_start <= `bannert1' + `bannerdur')) ;
bys bp: summ amt if curr=="USD";