help xtstfetchcovid19

Title

Downloads COVID-19 Datasets from the COVID-19 Data Hub

Syntax

xtstfetchcovid19
, options

pathz(string) indicates the complete file path where to save the new downloaded dataset. This option is required

granulev(#) designates the 3 different levels of granularity of the datasets. The values of # must be: 1, 2 or 3.
Default is granulev(1)

saving(filename [, replace]) allows to save the new downloaded dataset that the command downloads.
replace specifies that the file may be replaced if it already exists

Description

xtstfetchcovid19 downloads COVID-19 datasets from the COVID-19 Data Hub. The command xtstfetchcovid19 allows to
download COVID-19/CORONAVIRUS/SARS-CoV-2 datasets in Stata format at 3 different levels of granularity: country-level
data (level 1), state-level data (level 2) and city-level data (level 3). It permits to obtain time series and panel
datasets on numerous variables, such as: the number confirmed cases, deaths, recovered cases, tests, vaccines, people
vaccinated, hospitalized patients, people in intensive care unit, latitude, longitude, population, key google
mobility, key apple mobility, etc. The downloaded datasets can be aggregated at any frequency: daily, weekly, monthly,
yearly, etc. Cross-sections of the datasets can also be obtained after transforming the downloaded data. All these
datasets come from the COVID-19 Data Hub which is a website dedicated to make integrated COVID-19 data available to
the wider community of researchers around the world for a deeper insight into COVID-19.

Options

pathz(string) indicates the complete file path where to save the new downloaded dataset. In this option, you specify the
complete file path where you want to save the data downloaded by the command. If your file path contains blank spaces, you must enclose
the path in double quotes. This option is required.

granulev(#) designates the 3 different levels of granularity of the datasets. The values of # must be: 1, 2 or 3. These
numbers correspond to the 3 different levels of granularity of the datasets: administrative area of top-level, usually
countries (level 1); states, regions, cantons (level 2); and cities, municipalities (level 3). The default value of this
option is granulev(1), meaning that by default, country-level data (level 1) will be downloaded.

saving(filename [, replace]) allows to save the new downloaded dataset that the command
downloads. This option indicates the name of the diskfile to be created or replaced. If filename is specified without an
extension, .dta will be assumed. If the filename includes blank spaces, you must enclose the filename in double
quotes. The sub-option replace specifies that the file may be replaced if it already exists.

Examples

Before beginning the computations, we use the set more off instruction to tell
Stata not to pause when displaying the output.

set more off

In order to ease presentation and understanding, this Examples section is divided into 8 blocks. Each block
treats a different topic.

BLOCK 1

In this block, we illustrate how to use the command xtstfetchcovid19 with minimal syntax without saving the
data. We show how to extract the data for a group of countries (panel data) and for just one country (time series data).

We begin by writing the name of the command xtstfetchcovid19, followed by the option pathz(string). In this
option, we put, in double quotes, the complete file path where we want to save the data downloaded by the command. This option
is required.

Before continuing, a few notes on the pathz(string) option. Assume that you have Windows as your Operating
System and you want to save the data downloaded by the command xtstfetchcovid19 in a folder named "mystatagraphs" located
in the "C:\" drive. So, the full path name is "C:\mystatagraphs". Note that, you must physically create this folder; otherwise,
the next instruction will not work at all. Also, if you have an Operating System other than Windows, you must supply the
correct file path according to your Platform.

Since we do not specify the option granulev(#), the default value of this option is used, in
other words granulev(1). Meaning that by default, country-level data (level 1) will be downloaded.

\mystatagraphs")"'

The downloaded data do not come with labeled variables. But the variables names are
self-descriptive. Meaning that, if you show their full names, you can infer what they are.
Hence, we employ the describe command with the fullnames option to
see the full names of the variables of the downloaded dataset.

describe, fullnames

Also, for your information, all the variables that come with the datasets downloaded by the command xtstfetchcovid19 are
fully described in the article of Guidotti (2022). Thus, I strongly encourage you to take a look at this paper if you need
further information on the description of the variables that come with these datasets, please.

The previously downloaded database is a panel dataset for many countries in the world. If we want just to extract the
data for a smaller number of countries, for example: China, France, Italy and the United States, we type.

`"keep if (administrative_area_level_1 == "China" | administrative_area_level_1 == "France" | administrative_area_level_1 == "Italy" | administrative_area_level_1 == "United States")"'

If we just want to extract the data as a time series data for just one country, for example the United States, we type.

`"keep if administrative_area_level_1 == "United States""'

BLOCK 2

In this block, we demonstrate how to utilize the command xtstfetchcovid19 to save the daily data, set the date
to a Stata readable format and calculate the active cases.

To save the data, we specify the option saving(filename [, replace]) by indicating
the name of the file in which we want to save the downloaded database, in double quotes "covid19level1daily.dta". We also indicate
the sub-option replace, because we want to overwrite the file if it already exists.

\mystatagraphs") saving("covid19level1daily.dta", replace)"'

In the downloaded dataset "covid19level1daily.dta", the date is the variable named "date". To transform the content of
this variable to a Stata readable date format, we first get rid of the hyphen symbol by using the string
function subinstr() (please see [FN] functions for more details).

`"generate datest1 = subinstr(date,"-","",.)"'

Second, we transform the newly generated variable "datest1" to a Stata readable daily date by using the
date function daily() (please see [FN] functions for more details).

`"generate datest2 = daily(datest1, "YMD")"'

Third, we use the command format to change the newly generated variable "datest2" to a Stata days
calendar date format and to a human readable format (please see [D] format for more details).

`"format datest2 %td"'

Now, we sort the database by "administrative_area_level_1" and "datest2".

sort administrative_area_level_1 datest2

Then, we group the "administrative_area_level_1" variable by using the
command egen (please see [D] egen for more details).

egen adminarealevel1iden = group(administrative_area_level_1)

Finally, we declare the data to be daily panel data by using the
command xtset (please see [XT] xtset for more details).

xtset adminarealevel1iden datest2, daily

Now, we generate the Number of Active Cases of COVID-19. In fact, many of the variables that come with the downloaded
datasets by the command xtstfetchcovid19 represent Cumulative Number of Cases. But, for most practical statistical and
econometrical purposes, we are interested in the Number of Active Cases of COVID-19. In the next lines, we illustrate how to
calculate the Number of Active Cases by using the time-series operator D., which stands
for The First Difference Operator (please see [U] tsvarlist for more details).

generate double confirmedactive = D.confirmed

generate double deathsactive = D.deaths

generate double recoveredactive = D.recovered

In the 3 previous lines, we have created the number of active cases of confirmed, deaths and recovered respectively on a
daily basis for each country in our panel database.

We finish this block by saving all the changes we made to our dataset since we last downloaded it.

`"save "covid19level1daily.dta", replace"'

BLOCK 3

In this block, we mainly show how to aggregate the data at a weekly frequency.

We begin by downloading the data and saving them as we did previously.

\mystatagraphs") saving("covid19level1weekly.dta", replace)"'

Then, we perform the usual data managements we did in block 2. Please, see block 2 for more details on these data
managements.

`"generate datest1 = subinstr(date,"-","",.)"'

`"generate datest2 = daily(datest1, "YMD")"'

format datest2 %td

sort administrative_area_level_1 datest2

egen adminarealevel1iden = group(administrative_area_level_1)

xtset adminarealevel1iden datest2, daily

generate double confirmedactive = D.confirmed

generate double deathsactive = D.deaths

generate double recoveredactive = D.recovered

Now, we begin our weekly data aggregation. We start, by creating a weekly date by using the
function wofd() (please see [FN] functions for more details).

generate weeklydatest = wofd(datest2)

Then, we use the command format to change the newly generated variable "weeklydatest" to a Stata
calendar weeks format and to a human readable format (please see [D] format for more details).

`"format weeklydatest %tw"'

We sort the database by "administrative_area_level_1", "adminarealevel1iden", "iso_alpha_3",
and "weeklydatest".

sort administrative_area_level_1 adminarealevel1iden iso_alpha_3 weeklydatest

We aggregate the database at a weekly frequency by making a dataset of summary statistics by using the
command collapse (please see [D] collapse for more details).

collapse (sum) confirmedactive deathsactive recoveredactive (median) population, by(administrative_area_level_1 adminarealevel1iden iso_alpha_3 weeklydatest)

We sort the database by "administrative_area_level_1" and "weeklydatest".

sort administrative_area_level_1 weeklydatest

We declare the data to be weekly panel data by using the command xtset (please see [XT] xtset for more details).

xtset adminarealevel1iden weeklydatest, weekly

We finish this block by saving all the changes we made to our dataset since we last downloaded it.

`"save "covid19level1weekly.dta", replace"'

BLOCK 4

In this block, we mainly show how to aggregate the data at a monthly frequency.

We begin by downloading the data and saving them as we did previously.

\mystatagraphs") saving("covid19level1monthly.dta", replace)"'

Then, we perform the usual data managements we did in block 2. Please, see block 2 for more details on these data
managements.

`"generate datest1 = subinstr(date,"-","",.)"'

`"generate datest2 = daily(datest1, "YMD")"'

format datest2 %td

sort administrative_area_level_1 datest2

egen adminarealevel1iden = group(administrative_area_level_1)

xtset adminarealevel1iden datest2, daily

generate double confirmedactive = D.confirmed

generate double deathsactive = D.deaths

generate double recoveredactive = D.recovered

Now, we begin our monthly data aggregation. We start, by creating a monthly date by using the
function mofd() (please see [FN] functions for more details).

generate monthlydatest = mofd(datest2)

Then, we use the command format to change the newly generated variable "monthlydatest" to a Stata
calendar month format and to a human readable format (please see [D] format for more details).

`"format monthlydatest %tm"'

We sort the database by "administrative_area_level_1", "adminarealevel1iden", "iso_alpha_3",
and "monthlydatest".

sort administrative_area_level_1 adminarealevel1iden iso_alpha_3 monthlydatest

We aggregate the database at a monthly frequency by making a dataset of summary statistics by using the
command collapse (please see [D] collapse for more details).

collapse (sum) confirmedactive deathsactive recoveredactive (median) population, by(administrative_area_level_1 adminarealevel1iden iso_alpha_3 monthlydatest)

We sort the database by "administrative_area_level_1" and "monthlydatest".

sort administrative_area_level_1 monthlydatest

We declare the data to be monthly panel data by using the command xtset (please see [XT] xtset for more details).

xtset adminarealevel1iden monthlydatest, monthly

We finish this block by saving all the changes we made to our dataset since we last downloaded it.

`"save "covid19level1monthly.dta", replace"'

BLOCK 5

In this block, we mainly show how to aggregate the data at a yearly frequency.

We begin by downloading the data and saving them as we did previously.

\mystatagraphs") saving("covid19level1yearly.dta", replace)"'

Then, we perform the usual data managements we did in block 2. Please, see block 2 for more details on these data
managements.

`"generate datest1 = subinstr(date,"-","",.)"'

`"generate datest2 = daily(datest1, "YMD")"'

format datest2 %td

sort administrative_area_level_1 datest2

egen adminarealevel1iden = group(administrative_area_level_1)

xtset adminarealevel1iden datest2, daily

generate double confirmedactive = D.confirmed

generate double deathsactive = D.deaths

generate double recoveredactive = D.recovered

Now, we begin our yearly data aggregation. We start, by creating a yearly date by using the
function yofd() (please see [FN] functions for more details).

generate yearlydatest = yofd(datest2)

Then, we use the command format to change the newly generated variable "yearlydatest" to a Stata
calendar year format and to a human readable format (please see [D] format for more details).

`"format yearlydatest %ty"'

We sort the database by "administrative_area_level_1", "adminarealevel1iden", "iso_alpha_3",
and "yearlydatest".

sort administrative_area_level_1 adminarealevel1iden iso_alpha_3 yearlydatest

We aggregate the database at a yearly frequency by making a dataset of summary statistics by using the
command collapse (please see [D] collapse for more details).

collapse (sum) confirmedactive deathsactive recoveredactive (median) population, by(administrative_area_level_1 adminarealevel1iden iso_alpha_3 yearlydatest)

We sort the database by "administrative_area_level_1" and "yearlydatest".

sort administrative_area_level_1 yearlydatest

We declare the data to be yearly panel data by using the command xtset (please see [XT] xtset for more details).

xtset adminarealevel1iden yearlydatest, yearly

We finish this block by saving all the changes we made to our dataset since we last downloaded it.

`"save "covid19level1yearly.dta", replace"'

BLOCK 6

In this block, we mainly show how to aggregate the data as a cross-sectional database.

We begin by downloading the data and saving them as we did previously.

\mystatagraphs") saving("covid19level1crosssec.dta", replace)"'

Then, we perform the usual data managements we did in block 2. Please, see block 2 for more details on these data
managements.

`"generate datest1 = subinstr(date,"-","",.)"'

`"generate datest2 = daily(datest1, "YMD")"'

`"format datest2 %td"'

sort administrative_area_level_1 datest2

egen adminarealevel1iden = group(administrative_area_level_1)

xtset adminarealevel1iden datest2, daily

generate double confirmedactive = D.confirmed

generate double deathsactive = D.deaths

generate double recoveredactive = D.recovered

We sort the database by "administrative_area_level_1", "adminarealevel1iden" and "iso_alpha_3".

sort administrative_area_level_1 adminarealevel1iden iso_alpha_3

We aggregate the data as a cross-sectional database by making a dataset of summary statistics by using the
command collapse (please see [D] collapse for more details).

collapse (sum) confirmedactive deathsactive recoveredactive (median) population, by(administrative_area_level_1 adminarealevel1iden iso_alpha_3)

We sort the database by "administrative_area_level_1".

sort administrative_area_level_1

We finish this block by saving all the changes we made to our dataset since we last downloaded it.

`"save "covid19level1crosssec.dta", replace"'

BLOCK 7

In this block, we mainly show how to download states, regions and cantons level data (level 2).

We begin by downloading daily state-level data (level 2) by specifying the option granulev(2).

\mystatagraphs") granulev(2) saving("covid19level2daily.dta", replace)"'

The downloaded data do not come with labeled variables. But the variables names are
self-descriptive. Meaning that, if you show their full names, you can infer what they are.
Hence, we employ the describe command with the fullnames option to
see the full names of the variables of the downloaded dataset.

describe, fullnames

We perform the usual data managements we did in block 2, commenting only the lines that are new. Please, see
block 2 for more details on these data managements.

`"generate datest1 = subinstr(date,"-","",.)"'

`"generate datest2 = daily(datest1, "YMD")"'

`"format datest2 %td"'

We sort the database by "administrative_area_level_1", "administrative_area_level_2" and "datest2" because we
have state-level data (level 2).

sort administrative_area_level_1 administrative_area_level_2 datest2

We group the "administrative_area_level_1" and the "administrative_area_level_2" variables together because we
have state-level data (level 2) by using the command egen (please see [D] egen for more details).

egen adminarealevel2iden = group(administrative_area_level_1 administrative_area_level_2)

We declare the data to be daily panel data by using the command xtset (please see [XT] xtset for more details).

xtset adminarealevel2iden datest2, daily

generate double confirmedactive = D.confirmed

generate double deathsactive = D.deaths

generate double recoveredactive = D.recovered

We finish this block by saving all the changes we made to our dataset since we last downloaded it.

`"save "covid19level2daily.dta", replace"'

BLOCK 8

In this last block, we mainly show how to download cities and municipalities level data (level 3).

We begin by downloading daily city-level data (level 3) by specifying the option granulev(3).

\mystatagraphs") granulev(3) saving("covid19level3daily.dta", replace)"'

The downloaded data do not come with labeled variables. But the variables names are
self-descriptive. Meaning that, if you show their full names, you can infer what they are.
Hence, we employ the describe command with the fullnames option to
see the full names of the variables of the downloaded dataset.

describe, fullnames

We perform the usual data managements we did in block 2, commenting only the lines that are new. Please, see
block 2 for more details on these data managements.

`"generate datest1 = subinstr(date,"-","",.)"'

`"generate datest2 = daily(datest1, "YMD")"'

`"format datest2 %td"'

We sort the database by "administrative_area_level_1", "administrative_area_level_2", "administrative_area_level_3"
and "datest2" because we have city-level data (level 3).

sort administrative_area_level_1 administrative_area_level_2 administrative_area_level_3 datest2

We group the "administrative_area_level_1", the "administrative_area_level_2" and the
"administrative_area_level_3" variables together because we
have city-level data (level 3) by using the command egen (please see [D] egen for more details).

egen adminarealevel3iden = group(administrative_area_level_1 administrative_area_level_2 administrative_area_level_3)

We declare the data to be daily panel data by using the command xtset (please see [XT] xtset for more details).

xtset adminarealevel3iden datest2, daily

generate double confirmedactive = D.confirmed

generate double deathsactive = D.deaths

generate double recoveredactive = D.recovered

We finish this block by saving all the changes we made to our dataset since we last downloaded it.

`"save "covid19level3daily.dta", replace"'

EPILOGUE

The instructions we have shown in this Examples section, are just some of the few among the vast Data Management
tools that can be used with the datasets that the command xtstfetchcovid19 downloads. Hence, despite our efforts, we have
only scratched the surface of what can be done with the command xtstfetchcovid19, the accompanying downloaded
datasets, and the use of the command xtstfetchcovid19 in conjunction with the thousands excellent and wonderful
commands available from within Stata for Data Management, Data Analysis, Statistics, Econometrics and Data Science. We leave
these avenues of research to the reader/user to explore at her/his will !

References

Guidotti Emanuele and Ardia David: 2020,
"COVID-19 Data Hub",
Journal of Open Source Software 5(51), 2376.

Guidotti Emanuele: 2022,
"A worldwide epidemiological database for COVID-19 at fine grained spatial resolution",
Scientific Data 9(112).

COVID-19 Data Hub. Browsable at: https://covid19datahub.io.

Citation

The command xtstfetchcovid19 is not an Official Stata command. Like a paper, it is a free contribution to the research
community. If you find the command xtstfetchcovid19 and its accompanying datasets useful and utilize them in your
works, please cite them like a paper as it is explained in the Suggested Citation section of
the IDEAS/RePEc webpage of the command. Please, also cite Guidotti and Ardia (2020), Guidotti (2022) and
the website COVID-19 Data Hub in your
works.Thank you infinitely, in advance, for doing all these gestures! Please, note that citing this
command xtstfetchcovid19 and these references are a good way to disseminate their use and their
discovery by other researchers. Doing these actions, could also, potentially, help us, as a
community, to overcome COVID-19 and to help in solving other challenging current problems and those that lie ahead in the future.

Acknowledgements

I thank Emanuele Guidotti, David Ardia and all the Team of the COVID-19 Data Hub website for writing and making their
programs, data, articles and webpage publicly available. This current Stata package is based and inspired by their
works. The usual disclaimers apply: all errors and imperfections in this package are mine and
all comments are very welcome.

Author

Diallo Ibrahima Amadou

FERDI (Fondation pour les Etudes et Recherches sur le Developpement International)

63 Boulevard Francois Mitterrand

63000 Clermont-Ferrand

France

E-Mail: zavren@gmail.com

Also see

Online: help for [D] describe, [D] generate, [D] egen, [XT] xtset,
[D] save, [FN] functions, [D] format, [U] tsvarlist, [D] collapse,
probgenextval (if installed)