* Get the date right use "C:\My Documents\Numbercrunching\ECDC - COVID-19\temp1.dta", clear // This is the ECDC data obtained off https://www.ecdc.europa.eu/en/publications-data/download-todays-data-geographic-distribution-covid-19-cases-worldwide gen date = mdy(month, day, year) format date %td replace countryterritorycode = "CZE" if geoid=="CZ" drop if countryterritorycode=="" save "C:\My Documents\Numbercrunching\ECDC - COVID-19\temp2.dta", replace * Graph on cumulative deaths per day since first death use "C:\My Documents\Numbercrunching\ECDC - COVID-19\temp2.dta", clear rename countryterritorycode countryiso keep deaths countryiso date keep if deaths>0 by countryiso, sort: egen mindate = min(date) gen dayssince1 = date - mindate by countryiso (date), sort: gen deathscum = sum(deaths) drop if countryiso=="N/A" rename deathscum _ keep _ dayssince1 countryiso reshape wide _, i(dayssince1) j(countryiso) string foreach x of varlist * { if "`x'"!="dayssince1" { local temp = substr("`x'", 2, 3) rename `x' `temp' } } local totobs = _N local totobsminus = `totobs' - 1 forvalues i = `totobsminus' (-1) 1 { foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[`i']==. & `x'[`i' + 1]!=. { replace `x' = -9 in `i' } } } } forvalues i = 2 / `totobsminus' { foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[`i']==-9 { replace `x' = `x'[`i' - 1] in `i' } } } } summ dayssince1 if ZAF!=., det local maxZAF = r(max) local maxday = `maxZAF' + 7 summ ZAF, det local deathsZAF = r(max) local indicatorrow = `maxZAF' + 1 local countryset = 0 local worse = 0 local same = 0 foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[`indicatorrow']!=. { local countryset = `countryset' + 1 if `x'[`indicatorrow']>`deathsZAF' { local worse = `worse' + 1 } else { if `x'[`indicatorrow']==`deathsZAF' { local same = `same' + 1 } } } } } local same = cond(`same'>0, `same' - 1, 0) local graphstring = "" foreach x of varlist * { if "`x'"!="dayssince1" & "`x'"!="ZAF" { local graphstring = "`graphstring'" + " (line `x' day if day<=`maxday')" } } local labelstring = "" local maxdayplus = `maxday' + 1 local labelstring = "" foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[`maxdayplus']!=. { local deathshere = `x'[`maxdayplus'] local labelstring = `"`labelstring'"' + " `deathshere' `maxday' " + `""`x'""' // How to do this took almost two hours! } } } display `"`labelstring'"' local datadate = "7 April" // CHANGE DATE! #delimit ; twoway `graphstring' (line ZAF day if day<=`maxday', lwidth(thick) lcolor(red)), text(`labelstring', size(8pt)) ytitle("Cumulative deaths") xlabel(0(2)`maxday') // ADAPT THE SPACING (DELTA) AS NEEDED. xtitle("Days since first death in that country") note("According to `datadate' ECDC data, South Africa" "had `deathsZAF' deaths `maxZAF' days after the first death." "Of `countryset' countries with deaths by their" "day `maxZAF', `worse' had a higher (worse) value." "`same' had the same number of deaths." "The red line represents South Africa.", ring(0) position(12) size(10pt)) legend(off) graphregion(fcolor(white)) ; #delimit cr * Graph on cumulative deaths per 100000 normal deaths per day since first death use "C:\My Documents\Numbercrunching\ECDC - COVID-19\temp2.dta", clear rename countryterritorycode countryiso keep deaths countryiso date keep if deaths>0 merge m:1 countryiso using "C:\My Documents\Numbercrunching\UN data - sundry\deaths2017.dta", keepusing(deaths2017) keep if _merge==3 drop _merge drop if countryiso=="AND" // Andorra too strange. replace deaths = deaths / (deaths2017 / 100000) by countryiso, sort: egen mindate = min(date) gen dayssince1 = date - mindate by countryiso (date), sort: gen deathscum = sum(deaths) drop if countryiso=="N/A" rename deathscum _ keep _ dayssince1 countryiso reshape wide _, i(dayssince1) j(countryiso) string foreach x of varlist * { if "`x'"!="dayssince1" { local temp = substr("`x'", 2, 3) rename `x' `temp' } } local totobs = _N local totobsminus = `totobs' - 1 forvalues i = `totobsminus' (-1) 1 { foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[`i']==. & `x'[`i' + 1]!=. { replace `x' = -9 in `i' } } } } forvalues i = 2 / `totobsminus' { foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[`i']==-9 { replace `x' = `x'[`i' - 1] in `i' } } } } summ dayssince1 if ZAF!=., det local maxZAF = r(max) local maxday = `maxZAF' + 7 summ ZAF, det local deathsZAF = r(max) local indicatorrow = `maxZAF' + 1 local countryset = 0 local worse = 0 foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[`indicatorrow']!=. { local countryset = `countryset' + 1 if `x'[`indicatorrow']>`deathsZAF' { local worse = `worse' + 1 } } } } local graphstring = "" foreach x of varlist * { if "`x'"!="dayssince1" & "`x'"!="ZAF" { local graphstring = "`graphstring'" + " (line `x' day if day<=`maxday')" } } local maxdayplus = `maxday' + 1 local labelstring = "" foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[`maxdayplus']!=. { local deathshere: di %5.1f = `x'[`maxdayplus'] local labelstring = `"`labelstring'"' + " `deathshere' `maxday' " + `""`x'""' } } } display `"`labelstring'"' local deathsZAF: di %2.1f = `deathsZAF' #delimit ; twoway `graphstring' (line ZAF day if day<=`maxday', lwidth(thick) lcolor(red)), text(`labelstring', size(8pt)) ytitle("Cumulative COVID-19 deaths per 100,000 deaths" "in a typical year") xlabel(0(2)`maxday') // ADAPT THE SPACING (DELTA) AS NEEDED. xtitle("Days since first death in that country") note("`maxZAF' days after the first death in South Africa," "deaths per 100,000 deaths in a typical year" "came to `deathsZAF'." "Of `countryset' countries with deaths by their" "day `maxZAF', `worse' had a higher (worse) value." "The red line represents South Africa.", ring(0) position(12) size(10pt)) legend(off) graphregion(fcolor(white)) ; #delimit cr * As above, but covering the days of the country with the longest duration use "C:\My Documents\Numbercrunching\ECDC - COVID-19\temp2.dta", clear rename countryterritorycode countryiso keep deaths countryiso date keep if deaths>0 merge m:1 countryiso using "C:\My Documents\Numbercrunching\UN data - sundry\deaths2017.dta", keepusing(deaths2017) keep if _merge==3 drop _merge drop if countryiso=="AND" // Andorra too strange. replace deaths = deaths / (deaths2017 / 100000) by countryiso, sort: egen mindate = min(date) gen dayssince1 = date - mindate by countryiso (date), sort: gen deathscum = sum(deaths) drop if countryiso=="N/A" rename deathscum _ keep _ dayssince1 countryiso reshape wide _, i(dayssince1) j(countryiso) string foreach x of varlist * { if "`x'"!="dayssince1" { local temp = substr("`x'", 2, 3) rename `x' `temp' } } local totobs = _N local totobsminus = `totobs' - 1 forvalues i = `totobsminus' (-1) 1 { foreach x of varlist * { if "`x'"!="dayssince1" { local done = 0 if `x'[`i']==. & `x'[`i' + 1]!=. { replace `x' = -9 in `i' } } } } forvalues i = 2 / `totobsminus' { foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[`i']==-9 { replace `x' = `x'[`i' - 1] in `i' } } } } local graphstring = "" foreach x of varlist * { if "`x'"!="dayssince1" & "`x'"!="ZAF" { local graphstring = "`graphstring'" + " (line `x' day)" } } foreach x of varlist * { if "`x'"!="dayssince1" { quietly summ `x' local maxdays`x' = r(N) } } local graphstring = "" foreach x of varlist * { if "`x'"!="dayssince1" & "`x'"!="ZAF" { local graphstring = "`graphstring'" + " (line `x' day)" } } local labelstring = "" foreach x of varlist * { if "`x'"!="dayssince1" { local deathshere: di %2.1f = `x'[`maxdays`x''] local labelstring = `"`labelstring'"' + " `deathshere' `maxdays`x'' " + `""`x'""' } } display `"`graphstring'"' display `"`labelstring'"' local datadate = "7 April" // CHANGE DATE! #delimit ; twoway `graphstring' (line ZAF day, lwidth(thick) lcolor(red)), text(`labelstring', size(8pt)) ytitle("Cumulative COVID-19 deaths per 100,000 deaths" "in a typical year") xtitle("Days since first death in that country") note("This is like the previous graph," "except the maximum range of days is" "is shown", ring(0) position(12) size(10pt)) legend(off) graphregion(fcolor(white)) ; #delimit cr * Graph on cumulative cases over cumulative deaths use "C:\My Documents\Numbercrunching\ECDC - COVID-19\temp2.dta", clear rename countryterritorycode countryiso keep deaths cases countryiso date by countryiso (date), sort: gen casescum = sum(cases) summ casescum if countryiso=="ZAF" local casesZAF = r(max) keep if deaths>0 by countryiso, sort: egen mindate = min(date) gen dayssince1 = date - mindate by countryiso (date), sort: gen deathscum = sum(deaths) drop if countryiso=="N/A" gen _ = casescum / deathscum keep _ dayssince1 countryiso reshape wide _, i(dayssince1) j(countryiso) string foreach x of varlist * { if "`x'"!="dayssince1" { local temp = substr("`x'", 2, 3) rename `x' `temp' } } local totobs = _N local totobsminus = `totobs' - 1 forvalues i = `totobsminus' (-1) 1 { foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[`i']==. & `x'[`i' + 1]!=. { replace `x' = -9 in `i' } } } } forvalues i = 2 / `totobsminus' { foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[`i']==-9 { replace `x' = `x'[`i' - 1] in `i' } } } } summ dayssince1 if ZAF!=., det local maxZAF = r(max) local maxday = `maxZAF' + 7 local indicatorrow = `maxZAF' + 1 local countryset = 0 local worse = 0 local same = 0 local ratioZAF = ZAF[`indicatorrow'] foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[`indicatorrow']!=. { local countryset = `countryset' + 1 if `x'[`indicatorrow']<`ratioZAF' { local worse = `worse' + 1 } else { if `x'[`indicatorrow']==`ratioZAF' { local same = `same' + 1 } } } } } local same = cond(`same'>0, `same' - 1, 0) local graphstring = "" foreach x of varlist * { if "`x'"!="dayssince1" & "`x'"!="ZAF" { local graphstring = "`graphstring'" + " (line `x' day if day<=`maxday')" } } local labelstring = "" local maxdayplus = `maxday' + 1 local labelstring = "" foreach x of varlist * { if "`x'"!="dayssince1" { if `x'[3]!=. { local ratiohere = `x'[3] local labelstring = `"`labelstring'"' + " `ratiohere' 2 " + `""`x'""' } } } display `"`labelstring'"' local ratioZAF: di %1.0f = `ratioZAF' local datadate = "5 April" // CHANGE DATE! #delimit ; twoway `graphstring' (line ZAF day if day<=`maxday', lwidth(thick) lcolor(red)), text(`labelstring', size(8pt)) ytitle("Cumulative cases over cumulative deaths") xlabel(0(2)`maxday') // ADAPT THE SPACING (DELTA) AS NEEDED. xtitle("Days since first death in that country") note("`maxZAF' days after its first death" "South Africa had found `casesZAF' cases in total" "or `ratioZAF' cases per death. Of `countryset' countries with" "deaths by their day `maxZAF', `worse' had a lower (worse) value." "These ratios can be considered a measure" "of testing intensity" "The red line represents South Africa.", ring(0) position(12) size(10pt)) legend(off) graphregion(fcolor(white)) ; #delimit cr