![]() ![]() We use a forvalues loop and combine a horizontal bar chart with a scatterplot. Next we create a new graph for every single day from the start of data availability until today. rename date date_string gen date=date(date_string,"YMD") save "Hospital data.dta", replace local today: display date(c(current_date),"DMY") local date = td(15mar2020) // Create new graphs from this date local number_of_days =`today'-`date' Create the graphs ![]() local date = td(15jun2022) (this avoids having to recreate all the graphs from 15 March 2020 if you just want to add a limited number of new graphs). Next, we transform the original date variable (which is in string format) and create some locals to store the current date, the start date from which we want to create graphs and the number of days between start date and end date: 15 March 2020 is the first day of availability of the data, but if you want to update the animated graph, you may want to fill in a more recent date in the local date, e.g. import delimited " ", encoding("utf-8") encode province, generate(province2) label define province2 2 "Brabant Wallon", modify label define province2 9 "Oost-Vlaanderen", modify label define province2 10 "Vlaams-Brabant", modify label define province2 11 "West-Vlaanderen", modify gen Share_ICU_beds=0 replace Share_ICU_beds = total_in_icu/301 if province="Antwerpen" replace Share_ICU_beds = total_in_icu/23 if province="BrabantWallon" replace Share_ICU_beds = total_in_icu/278 if province="Brussels" replace Share_ICU_beds = total_in_icu/259 if province="Hainaut" replace Share_ICU_beds = total_in_icu/230 if province="Liège" replace Share_ICU_beds = total_in_icu/145 if province="Limburg" replace Share_ICU_beds = total_in_icu/43 if province="Luxembourg" replace Share_ICU_beds = total_in_icu/97 if province="Namur" replace Share_ICU_beds = total_in_icu/265 if province="OostVlaanderen" replace Share_ICU_beds = total_in_icu/139 if province="VlaamsBrabant" replace Share_ICU_beds = total_in_icu/221 if province="WestVlaanderen" replace Share_ICU_beds = Share_ICU_beds*100 gen max_share_ICU_beds=0 // To keep track of the maximum share of occupied beds up to a given day 301 in Antwerpen, 23 in Brabant Wallon, etc.). We first import the data, change some of the labels and create a new variable called ‘Share_ICU_beds’ that allows to calculate the share of ICU beds occupied by Covid-patients (using the total number of ICU beds in every province, e.g. This example uses data on Covid-patients in Belgian hospitals. cd "C:/COVID19animation" Import data and basic data manipulation So first I set the working directory to this folder ‘COVID19animation’: in this case it will look like the command below (you can change it into the combination of folders and subfolders where you want to locate the files). In order not to distract from the main aim of creating an animated graph, I will simply store all files in one folder: the hypothetical folder called ‘COVID19animation’ which is simply located in the root of my C-drive. Before starting, it is always a good idea to set up a decent folder structure and to store data, graphs and other objects in different folders: see The Stata workflow guide for an excellent overview.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |