## Wednesday, April 1, 2020

### Mapping COVID-19: Follow-up

As a follow up to our previous blog entry describing how to import Covid-19 data into EViews and produce some maps/graphs of the data, this post will produce a couple more graphs similar to ones we've seen become popular across social media in recent days.

### Deaths Since First Death

The first is a graph showing the 3 day moving average of the number of deaths per day since the first death was recorded in a country, for countries with a current number of deaths greater than 160:

 Figure 1: 3-Day moving average

The graph shows that for most countries the growth rate of deaths (approximated by using log-scaling) is increasing, but at a slower rate. The code to produce this graph, including importing the death data from Johns Hopkins is:

    'import the death data from Johns Hopkins
%url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv"

'load up the url as a new page

'stack the page into a 2d panel
pagestack(page=stack) _? @ *? *

'do some renaming and make the date series
rename country_region country
rename province_state province
rename _ deaths
series date = @dateval(var01, "MM_DD_YYYY")

'structure the page
pagestruct province country @date(date)

'delete the original page
pagedelete temp

'create the panel page
pagecreate(id, page=panel) country @date @srcpage stack

'copy the deaths series to the panel page
copy(c=sum) stack\deaths * @src @date country @dest @date country
pagedelete stack

'contract the page to only include countries with greater than 160 deaths
pagecontract if @maxsby(deaths,country)>160

'create a series containing the number of days since the first death was recorded in each country.  This series is equal to 0 if the number of deaths on a date is equal to the minimum number of deaths for that country (nearly always 0, but for China, the data starts after the first recorded death), and then counts up by one for dates after the minimum.
series days = @recode(deaths=@minsby(deaths,country), 0, days(-1)+1)

'contract the page so that days before the second recorded death in each country are removed
pagecontract if days>0

'restructure the page to be based on this day count rather than actual dates
pagestruct(freq=u) @date(days) country

'set sample to be first 45 days
smpl 1 45

'make a graph of the 3 day moving average of deaths
freeze(d_graph) @movav(log(deaths),3).line(m, panel=c)
d_graph.addtext(t, just(c)) Deaths Since First Death\n(3 day moving average, log scale)
d_graph.legend columns(5)
d_graph.legend position(-0.6,3.72)
show d_graph


### One Week Difference

The second graph is an interesting approach plotting the one-week difference in the number of new confirmed cases of COVID-19 against the total number of confirmed cases for each country, with both shown using log-scales. We have only included countries with more than 140 deaths, and have highlighted just three countries – China, South Korea and the US.

 Figure 2: One week difference

The code to generate this graph is:

    'names of the three topics/files
%topics = "confirmed deaths recovered"

'loop through the topics
for %topic {%topics}

'build the url by taking the base url and then adding the topic in the middle
%url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_" + %topic + "_global.csv"

'load up the url as a new page

'stack the page into a 2d panel
pagestack(page=stack_{%topic}) _? @ *? *

'do some renaming and make the date series
rename country_region country
rename province_state province
rename _ {%topic}
series date = @dateval(var01, "MM_DD_YYYY")

'structure the page
pagestruct province country @date(date)

'delete the original page
pagedelete temp
next

'create the panel page
pagecreate(id, page=panel) country @date @srcpage stack_{%topic}

'loop through the topics copying each from the 2D panel
for %topic {%topics}
copy(c=sum) stack_{%topic}\{%topic} * @src @date country @dest @date country
pagedelete stack_{%topic}
next

'contract the page to only include countries with more than 140 deaths
pagecontract if @maxsby(deaths, country)>140

'make a group, called DATA, containing confirmed cases and the one week difference in confirmed cases
group data confirmed confirmed-confirmed(-7)

'set the sample to remove periods with fewer than 50 cases
smpl if confirmed > 50

'produce a panel plot of confirmed against 7 day difference in confirmed
freeze(c_graph) data.xyline(panel=c)

c_graph.addtext(t) "COVID-19: New vs. Total Cases\n(Countries with >140 deaths)"
c_graph.addtext(bc, just(c)) "Total Confirmed Cases\n(log scale)"
c_graph.addtext(l, just(c))"New Confirmed Cases (in the past week)\n(log scale)"
c_graph.setelem(1) legend("")

' Adjust axis to use logs
c_graph.axis(b) log
c_graph.axis(l) log

' Adjust lines  -   remove lines after this if you want to show all countries
c_graph.legend -display
for !i = 1 to @rows(@uniquevals(country))
c_graph.setelem(!i) linewidth(.75) linecolor(@rgb(192,192,192))
next

c_graph.setelem(8) linecolor(@rgb(128,64,0))
c_graph.setelem(3) linecolor(@rgb(0,64,128))
c_graph.setelem(15) linecolor(@rgb(0,128,0))

c_graph.addtext(3.29, 1.92, font(Calibri,10))  "S. Korea"
c_graph.addtext(4.87, 2.35, font(Calibri,10))  "China"
c_graph.addtext(5.31, 0.23, font(Calibri,10))  "United States"

show c_graph


1. Hello EViews Team.
Great Work. Felicitations.
Very Thanks.

2. HELLO EViews Team. Please, how could l download the population by country data from the site of Johns Hopkins Whiting School of Engineering Center for Systems Science and Engineering? For example in an CSV file?
Cordially

3. HELLO EViews Team. Please, on EViews how can we do a forecast by distribution?

4. Hello EViews team, I have prepared a small program on EViews, but l still have a doubt: in the logistic model, On what basis K=b1-1 (k= the max value)?

/ The logistic model: C=b1/(1+b2*exp(-b2*trend))

Best wishes.

5. This comment has been removed by the author.

6. Hello, assuming we have the following two methods to determine the peack point;

1st Method: Estimate the logistic model for the cumulative number of infected cases i.e. d(hat(C)), then we look for the peack date (The return point of the function).

2nd Method: Estimate the derived function of the logistic model for the number of infected cases per day i.e. hat(d(C)), then we look for the peack date (The max of the function).

Please, what is the best method, because the two methods do not have the same result?

Cordially.

7. This comment has been removed by a blog administrator.

8. Thanks for your work!