help xtstgathercovid19

Title

Downloads COVID-19 Data from Our World in Data

Syntax

xtstgathercovid19
, options

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

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

xtstgathercovid19 downloads COVID-19 Data from Our World in Data. The command xtstgathercovid19 allows to
download COVID-19/CORONAVIRUS/SARS-CoV-2 data in Stata format. It permits to obtain time series and panel
datasets on numerous variables, such as: new cases, new deaths, new vaccinations, stringency index, reproduction
rate, population, etc. The downloaded datasets can be aggregated at any frequency: daily, weekly, monthly, quarterly,
yearly, etc.
Cross-sections of the datasets can also be obtained after transforming the downloaded data. All these datasets
come from Our World in Data which is a website dedicated to sharing the necessary research and data to address
and overcome the most significant global challenges.

Important Information

I wrote the command xtstgathercovid19 at the request of the readers/users of my previous
command xtstfetchcovid19 (if installed). The two commands xtstgathercovid19
and xtstfetchcovid19 are complementary. The typical use case scenario is
that, you utilize the two commands to download the necessary variables or databases you need for
your specific study from both commands in order to suit your particular analysis, because
there are some variables, some temporal depths or datasets that exist in one command that are not in the other and vice versa.

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.

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 6 blocks. Each block
treats a different topic.

BLOCK 1

In this block, we illustrate how to use the command xtstgathercovid19 to extract the data for a
group of countries (panel data) and for just one country (time series data). We also demonstrate how to utilize
the command xtstgathercovid19 to save the daily data and set the date to a Stata readable format.

We begin by writing the name of the command xtstgathercovid19, 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. 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 "covid19compantsdaily1.dta". We also
indicate the sub-option replace, because we want to overwrite the file if it already exists.

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 xtstgathercovid19 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.

\mystatagraphs") saving("covid19compantsdaily1.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

In this described database, we notice that Stata gave us the full name of each
variable. It also, automatically labeled the variable names that was truncated.

In the downloaded dataset "covid19compantsdaily1.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"'

Fourth, we reorder the variables in the dataset (please see [D] order for more details).

order code continent country date datest2

Fifth, we drop potential duplicate observations in the
dataset (please see [D] duplicates for more details).

`"bysort country datest2: keep if _n == 1"'

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

sort country datest2

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

egen countryiden = group(country)

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

xtset countryiden datest2, daily

Now, we keep only a few important variables that might be of interest to us
(please see [D] drop for more details).

keep code continent country datest2 new_cases new_deaths new_vaccinations stringency_index reproduction_rate population

Next, we save all the changes we made to our daily dataset since we last downloaded it.

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

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 (country == "China" | country == "France" | country == "Italy" | country == "United States")"'

Now, we save the changes we just made previously into a new dataset.

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

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 country == "United States""'

Now, we finish this block, by saving the changes we just made previously into a new dataset.

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

BLOCK 2

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("covid19compantsweekly.dta", replace)"'

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

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

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

format datest2 %td

order code continent country date datest2

bysort country datest2: keep if _n == 1

sort country datest2

egen countryiden = group(country)

xtset countryiden datest2, daily

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 "country", "countryiden", "code",
and "weeklydatest".

sort country countryiden code 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) new_cases new_deaths new_vaccinations (median) stringency_index reproduction_rate population, by(country countryiden code weeklydatest)

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

sort country weeklydatest

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

xtset countryiden weeklydatest, weekly

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

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

BLOCK 3

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("covid19compantsmonthly.dta", replace)"'

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

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

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

format datest2 %td

order code continent country date datest2

bysort country datest2: keep if _n == 1

sort country datest2

egen countryiden = group(country)

xtset countryiden datest2, daily

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 "country", "countryiden", "code",
and "monthlydatest".

sort country countryiden code 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) new_cases new_deaths new_vaccinations (median) stringency_index reproduction_rate population, by(country countryiden code monthlydatest)

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

sort country monthlydatest

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

xtset countryiden monthlydatest, monthly

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

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

BLOCK 4

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

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

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

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

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

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

format datest2 %td

order code continent country date datest2

bysort country datest2: keep if _n == 1

sort country datest2

egen countryiden = group(country)

xtset countryiden datest2, daily

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

generate quarterlydatest = qofd(datest2)

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

`"format quarterlydatest %tq"'

We sort the database by "country", "countryiden", "code",
and "quarterlydatest".

sort country countryiden code quarterlydatest

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

collapse (sum) new_cases new_deaths new_vaccinations (median) stringency_index reproduction_rate population, by(country countryiden code quarterlydatest)

We sort the database by "country" and "quarterlydatest".

sort country quarterlydatest

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

xtset countryiden quarterlydatest, quarterly

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

`"save "covid19compantsquarterly.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("covid19compantsyearly.dta", replace)"'

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

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

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

format datest2 %td

order code continent country date datest2

bysort country datest2: keep if _n == 1

sort country datest2

egen countryiden = group(country)

xtset countryiden datest2, daily

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 "country", "countryiden", "code",
and "yearlydatest".

sort country countryiden code 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) new_cases new_deaths new_vaccinations (median) stringency_index reproduction_rate population, by(country countryiden code yearlydatest)

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

sort country yearlydatest

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

xtset countryiden yearlydatest, yearly

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

`"save "covid19compantsyearly.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("covid19compantscrosssec.dta", replace)"'

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

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

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

`"format datest2 %td"'

order code continent country date datest2

bysort country datest2: keep if _n == 1

sort country datest2

egen countryiden = group(country)

xtset countryiden datest2, daily

We sort the database by "country", "countryiden" and "code".

sort country countryiden code

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) new_cases new_deaths new_vaccinations (median) stringency_index reproduction_rate population, by(country countryiden code)

We sort the database by "country".

sort country

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

`"save "covid19compantscrosssec.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 xtstgathercovid19 downloads. Hence, despite our efforts, we have
only scratched the surface of what can be done with the command xtstgathercovid19, the accompanying downloaded
datasets, and the use of the command xtstgathercovid19 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

Edouard Mathieu, Hannah Ritchie, Lucas Rodés-Guirao, Cameron Appel, Daniel Gavrilov, Charlie Giattino, Joe Hasell, Bobbie Macdonald, Saloni Dattani, Diana Beltekian, Esteban Ortiz-Ospina and Max Roser: 2020,
"COVID-19 Pandemic",
Our World in Data.

Our World in Data. Browsable at: https://ourworldindata.org/coronavirus.

Citation and Donation

The command xtstgathercovid19 is not an Official Stata command. Like a paper, it is a free contribution to
the research community. If you find the command xtstgathercovid19 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 Edouard Mathieu et al. (2020)
and the website Our World in Data in your
works. Additionally, I encourage you, please, to visit the Our World in Data website, because it contains
many important scientific articles and awesome information on the COVID-19 Pandemic that will help you
in your COVID-19/CORONAVIRUS/SARS-CoV-2 modeling and analysis journeys.
Thank you infinitely, in advance, for doing all these gestures! Please, note that citing this
command xtstgathercovid19 and these references are a good way to disseminate their use and their
discovery by other researchers and analysts. 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.

I would also like to ask you about one more thing, please! I hope you are finding my Stata Packages useful
and insightful. If you have appreciated the work I do and would like to support me financially in continuing
to develop these resources, I would be incredibly grateful. You can help fund my work
through My Patreon Page (LINK HERE)
or through My PayPal Page (LINK HERE),
which will allow me to dedicate more time and resources to creating even better
tools and updates. Any contribution, no matter how small, is greatly appreciated
and will go directly towards furthering my work.
Thank you so much in advance for your valuable support ! Best and Kind Regards !

Acknowledgements

I thank Edouard Mathieu, Hannah Ritchie, Lucas Rodés-Guirao, Cameron Appel, Daniel Gavrilov, Charlie Giattino,
Joe Hasell, Bobbie Macdonald, Saloni Dattani, Diana Beltekian, Esteban Ortiz-Ospina and Max Roser; all the Team
of the Our World in Data website; and all their original third-party data providers authors 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

Diallo Ibrahima Amadou

Zavren Consulting and Publishing

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, [D] order, [D] duplicates, [D] drop,
probgenextval (if installed), xtstfetchcovid19 (if installed)