In this exercise I took a database with close to 500 observations for 25 variables. From this database I selected 50 observations for 5 variables. This was done basically in two steps. I eliminated the variables I am not interested in and selected only countries in Latin America.
My ultimate aim is to analyze disparities across four child-related indicators in Latin America. The axes of disparities are: sex, urban-rural location, mothers’ education, and sub-national political administrative units (admin level 1).
As a first step, in this exercise, I am putting together the data for birth registration. I am only including sex (male/female) disaggregation.
#Steps
In order to set the data up, I exported the data from the UNICEF Data Warehouse and saved them as a CSV file in Github.
The url is:
Then, I brought the data from GitHub to RStudio. I followed the instructions in the assignment and using the url where I placed the data in GitHub:
url<- “https://raw.githubusercontent.com/Enrique01234/607-Fall-2026/refs/heads/main/Copy%20of%20fusion_GLOBAL_DATAFLOW_UNICEF_1.0_.PT_CHLD_Y0T4_REG..csv” df <- read_csv( + file = url, + show_col_types = FALSE, + progress = FALSE)
In the Environment Pane, I can see there are 495 observations and 25 variables in the data frame called “df”.
In order to check the names of the columns (variables), I use
colnames (df)
Now, not only can I see the names, I can also know their location: the columns are numbered according to their position in the data frame. This is what is needed to select the subset of variables I am interested in.
The columns I am interested in are: “REF_AREA CTRY” (which has the name of the country of the observation), “Region” (which has a numeric code for geographic regions such as South Asia or Western and Central Africa; Latin America is coded as 1), “TIME_PERIOD” (the year of the observation), “SEX” ( a code shows if the value is for the whole country, “_T”, only boys, “M”, or only girls “F”), and “OBS_VALUE” (which is the actual number, the percentage of children whose birth is registered before they reach age 5).
I did this in two different ways
I specifically selected the columns I am interested in and crated a new data frame called “new_dftotry”:
new_dftotry <- df[,+c(4, 5, 7, 8, 9)]
In the Environment Pane, I can see there are 495 observations and 25 variables in the data frame called “new_dftotry”.
I can see the result using
new_dftotry
I also tried a longer way, by eliminating all variables except “REF_AREA CTRY”, “Region”, “TIME_PERIOD”, “SEX”, and “OBS_VALUE”. It might be easier to select the ones I am interested in, but I was exploring the select function and I wanted to check using the minus sign.
new_df2 <- df[, -c(1, 2, 3, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,25)]
The new data frame, called “new_df2”, has 5 columns and 495 observations, which I can check with:
new_df2
It gives the same result as new_dftotry
Please notice there is also a data frame called “new_df”. I created it while I was exploring the select function but it did not work as expected, I had not managed to delete all the variables I wanted to delete.
Finally, I selected only the countries in Latin America. The result is a new data frame called “LatAm”.
LatAm <- subset (new_df2,
+ Region == “1”)
The new data frame has 5 columns and 50 observations, as can be seen in the Environment pane and using
LatAm
#Conclusion
There are 50 observations in the LatAm data frame. Some of them are the only observation for a country. This is the case for Chile (CHL), Costa Rica (CRI), and Venezuela (VEN) as they appear only once and the SEX column shows “_T”. However, for most countries there are three observations (with information for the whole country, “_T” and disaggregated between boys, “M”, and girls, “F”). Using code, I would like to count the number of countries.
Countries without male/female disaggregation would have to be separated from the ones without disaggregation. However, they should not be deleted as the same countries may have disaggregation by urban-rural or other axes of disparity, which could be used for further analysis.
I would also like to check the most recent year with data. It seems to be 2023, but I want to find this out using code. Also, how many countries? How many countries with data in either 2023 or 2022?