-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipumsr_webinar.Rmd
2302 lines (1460 loc) · 52.7 KB
/
ipumsr_webinar.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Enhancing reproducibility with the IPUMS API and the ipumsr package"
author: "Derek Burk, Dan Ehrlich, & Kara Fisher"
date: "4/11/2022"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
highlightSpans: true
countIncrementalSlides: false
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
collapse = TRUE,
comment = "#>"
)
hook_source <- knitr::knit_hooks$get('source')
knitr::knit_hooks$set(source = function(x, options) {
x <- gsub(
"^[[:blank:]]?([^*].+?)[[:blank:]]*#<<[[:blank:]]*$",
"*\\1",
x,
perl = TRUE
)
hook_source(x, options)
})
options(width = 50)
```
<style>
.derek-pet {
background-color: #000000;
background-image: url(images/derek2.jpg);
background-size: cover;
width: 120px;
height: 160px;
position: absolute;
left: 125px;
top: 150px;
}
</style>
<style>
.dan-pet1 {
background-color: #d3d3d3;
background-image: url(images/felix.jpg);
background-size: cover;
width: 120px;
height: 160px;
position: absolute;
left: 305px;
top: 225px;
}
</style>
<style>
.dan-pet2 {
background-color: #000000;
background-image: url(images/luna.jpg);
background-size: cover;
width: 120px;
height: 120px;
position: absolute;
left: 450px;
top: 250px;
}
</style>
<style>
.kara-pet1 {
background-color: #000000;
background-image: url(images/Ru.jpg);
background-size: cover;
width: 120px;
height: 160px;
position: absolute;
left: 600px;
bottom: 200px;
}
</style>
<style>
.kara-pet2 {
background-color: #000000;
background-image: url(images/harvey.jpg);
background-size: cover;
width: 120px;
height: 160px;
position: absolute;
left: 730px;
bottom: 200px;
}
</style>
<style>
.grid-logo {
background-image: url(images/grid.png);
background-size: cover;
width: 400px;
height: 400px;
position: absolute;
right: 75px;
}
</style>
<style>
.isrdi-logo {
background-image: url(images/isrdi2.jpg);
background-size: cover;
height: 186px;
width: 604px;
position: absolute;
bottom: 15px;
left: 15;
}
</style>
<style>
.names {
font-size: 1.5em;
}
</style>
<style>
.greyed-out {
color: #D3D3D3;
text-indent: 20px;
}
</style>
<style>
.strong {
color: #000000;
text-indent: 20px;
}
</style>
# Who we are
.isrdi-logo[
]
--
.left[
Derek Burk, PhD
Sociology
]
--
.center[
Dan Ehrlich, MA
Anthropology
]
--
.right[
Kara Fisher,
MPH
Public Health
]
???
(Name, pronouns, academic field, time with IPUMS)
So, my name is Derek Burk, my pronouns are he/him, I've been working on the
IPUMS International team for the past four years, and my academic training is in
sociology.
---
# Who we are
.isrdi-logo[]
.derek-pet[
]
.dan-pet1[]
.dan-pet2[]
.kara-pet1[]
.kara-pet2[]
???
Rather than our faces, we thought everyone would appreciate pets.
**A FEW NOTES**
This presentation will be recorded and will be available along with slides so don't worry about trying to take notes.
You can always reach out to through our **github**, or via **user support**.
---
# Overview
1. What is IPUMS?
--
2. What is ipumsr, and why use it?
--
3. How to create a data extract
--
4. Reading data into R
--
5. Exploring and manipulating metadata
--
6. Intro to the IPUMS USA API
--
7. IPUMS API use cases
--
8. Q & A
---
# Overview
.greyed-out[
.strong[`1.` What is IPUMS?]
`2.` What is ipumsr, and why use it?
`3.` How to create a data extract
`4.` Reading data into R
`5.` Exploring and manipulating metadata
`6.` Intro to the IPUMS USA API
`7.` IPUMS API use cases
`8.` Q & A
]
---
class: center
# What is IPUMS?
--
## IPUMS is **data**
## from censuses and surveys around the world,
## **harmonized** across space and time,
## thoroughly documented,
## and available for free at ipums.org
???
ipums has grown substantially since its first beta release in 1993,
started with **US census data** has grown to include 9 collections
---
# Harmonization
```{r echo=FALSE, fig.alt="Table illustrating IPUMS harmonization process.", fig.height=3, fig.width=5}
knitr::include_graphics("images/harmonization_4.png")
```
---
#
![IPUMS US Project logo](images/usa.jpg)
- U.S. Census and American Community Survey **microdata** from 1850 to the present.
- 180,755,919 unique person records from decennial census and American Community Survey.
- 191,983,898 historical person records from full count decennial census from 1850-1940 (1890 census lost due to fire).
- https://usa.ipums.org/usa/
???
---
#
![IPUMS CPS project logo](images/cps.jpg)
- Current Population Survey **microdata** from 1962 to the present.
- Monthly labor force surveys and supplements.
- https://cps.ipums.org/cps/
---
#
![IPUMS Health Surveys project logo](images/health.jpg)
- Health **survey** data from the National Health Interview Survey (NHIS) from the 1960s to the present and the Medical Expenditure Panel Survey (MEPS) from 1996.
- Supplements on cost of healthcare.
- https://healthsurveys.ipums.org/
???
---
#
![IPUMS Higher Ed project logo](images/highered.jpg)
- Scientists and Engineers Statistical Data System (SESTAT), the leading surveys for studying the science and engineering (STEM) workforce in the United States
- Data from the National Surveys of College Graduates (NSCG), Recent College Graduates (NSRCG) and Doctorate Recipients (SDR) are integrated from 1993 to the present.
- https://highered.ipums.org/highered/
---
#
![IPUMS international project logo](images/int.jpg)
- Census **microdata** covering 103 countries from 1960 to the present
- International historic **microdata** from the 19th and early 20th centuries available for some samples.
- Labor Force surveys provide high resolution **microdata** about work conditions
- Administered quarterly (usually) with records going back at least 10 years (usually)
- Currently available for Italy (2011-2020), Spain (2005-2020), and Mexico (2005-2020)
- https://international.ipums.org/international/
---
#
![IPUMS international project logo](images/int.jpg)
.pull-left[
- “Climate-Induced migration and unemployment in middle-income Africa”
- Valerie Mueller, Clark Gray, and Douglas Hopping
]
.pull-right[
![Maps of migration, education, temperature, and precipitation for 3 counties.](images/example_international.png)
]
---
#
![IPUMS Global Health project logo](images/dhs.jpg)
- Demographic and Health Surveys (DHS) provide integrated **microdata** for analysis across time and space.
- From the 1980s to the present.
- Covering Africa and South Asia
- Performance Monitoring for Action (PMA) surveys
- Focus on fertility, contraception, hygiene, and health
- Administered frequently to monitor trends in select high-fertility countries.
- https://globalhealth.ipums.org/
---
#
![IPUMS Global Health project logo](images/dhs.jpg)
.pull-left[
![alluvial plot showing which individuals were using family planning at two points in time](images/example_global_health.png)
]
.pull-right[
- https://tech.popdata.org/pma-data-hub/
]
???
Check out blog using IPUMS Global Health Data
---
.pull-left[
![IPUMS NHGIS project logo](images/nhgis.jpg)
]
.pull-right[
![IPUMS IHGIS project logo](images/ihgis.jpg)
]
.pull-left[
- **NHGIS** Shapefiles for all levels of US geography including tracts, from 1790 to the present
- https://www.nhgis.org/
]
.pull-right[
- **IHGIS** Shapefiles for admin level 2
- https://ihgis.ipums.org/
]
- Summary tables and time series of population, housing, agriculture, and economic data
---
![IPUMS NHGIS project logo](images/nhgis.jpg)
- “Migrant Selection and Sorting during the Great American Drought.”
- Christopher Sichko
.pull-left[
![map showing extent of drought](images/example_nhgis1.png)
]
.pull-right[
![map showing educational achievement by region](images/example_nhgis2b.png)
]
---
#
![IPUMS Time Use project logo](images/time_use.jpg)
- Historical and contemporary time use data from 1965 to the present.
- Extensive time diary data from respondents in the US and *7* other countries.
- https://timeuse.ipums.org/
---
#
![IPUMS Time Use project logo](images/time_use.jpg)
.pull-left[
- Nathan Yau of Flowing Data
- http://flowingdata.com/projects/2015/timeuse-simulation/
]
.pull-right[
!["Visualization of individuals (dots) moving between activity categories."](images/example_time_use.png)
]
---
# So what is IPUMS?
.grid-logo[
]
.pull-left[
- IPUMS is **a lot** of data
- Individual-level microdata
- Summarized tabular data
- GIS shapefiles
- Consistent and extensively documented **metadata**
]
???
So ipums really is **data** and a whole lot of it. These 9 different projects interact with different types of data and at different scales but they are united in the use of metadata that helps contextualize the data
*So I know you're asking yourselves..*
---
# So what is IPUMS?
.grid-logo[
]
.pull-left[
- IPUMS is **a lot** of data
- Individual-level microdata
- Summarized tabular data
- GIS shapefiles
- Consistent and extensively documented **metadata**
- *How can I work with all this IPUMS data?*
]
???
---
# Overview
.greyed-out[
`1.` What is IPUMS?
.strong[`2.` What is ipumsr, and why use it?]
`3.` How to create a data extract
`4.` Reading data into R
`5.` Exploring and manipulating metadata
`6.` Intro to the IPUMS USA API
`7.` IPUMS API use cases
`8.` Q & A
]
---
# What is ipumsr?
<style>
.ipumsr-logo {
background-image: url(images/ipumsr.png);
background-size: cover;
height: 298px;
width: 257px;
position: absolute;
right: 50px;
bottom: 50px;
}
</style>
.ipumsr-logo[
]
- R package developed by Greg Freedman Ellis
- Released in 2017
- Over 100,000 CRAN downloads
- Includes functions for
- Reading IPUMS data
- Exploring and manipulating IPUMS metadata
- **SOON**: Interacting with the IPUMS API
???
(Metadata such as value labels, variable labels, and detailed variable
descriptions.)
Initial API support will be for IPUMS USA, with more projects to follow soon.
---
# Why use ipumsr?
- One package for IPUMS microdata, aggregate data, and geography
- Specialized functions for viewing and manipulating IPUMS metadata
- Bundled how-to guides (vignettes)
- Potential to add more features (e.g. API support); let us know what you want!
- File an issue at https://github.com/ipums/ipumsr/issues
- Email [email protected]
???
Regarding "One package": Without ipumsr, you'd need to use a variety of
different approaches from different packages to read in and explore IPUMS
**microdata** from IPUMS: USA, CPS, and International, IPUMS
**aggregate data** (from NHGIS or IHGIS),
and **IPUMS shapefiles**. ipumsr provides one
package with a consistent interface for working with all these different types
of IPUMS data.
*a one stop shop that makes it easy to work with ipums data*
Regarding "More features": The aforementioned IPUMS API support will be the next
big feature. Another potential new feature is adding tools for properly handling
survey weights. Let us know what would be helpful to you via GitHub or email.
---
class: center, middle
# To run the code in this presentation
???
Repeat: slides/recording will be available. To run this code yourself you can clone/download the repo from our github. This provides the data extracts you'll need.
However, you may need to install some additional packages used in the example code below, as shown on the next slide.
---
.pull-left[
# Install R packages (as needed)
```{r, eval = FALSE}
install.packages("ipumsr")
## Tidyverse
install.packages("dplyr")
install.packages("ggplot2")
install.packages("stringr")
install.packages("purrr")
## HTML tables
install.packages("DT")
## GitHub helper functions
install.packages("usethis")
```
]
.pull-right[
# Load R packages (each time)
```{r, eval = FALSE}
library(ipumsr)
## Tidyverse
library(dplyr)
library(ggplot2)
library(stringr)
library(purrr)
## HTML tables
library(DT)
## GitHub helper functions
library(usethis)
```
]
```{r, echo = FALSE, include=FALSE}
library(ipumsr)
## Tidyverse
library(dplyr)
library(ggplot2)
library(stringr)
library(purrr)
## HTML tables
library(DT)
## GitHub helper functions
library(usethis)
```
???
reminder, installing packages only needs to happen once, but some packages do update frequently so it can be a good idea to re-install once in a while
---
# Overview
.greyed-out[
`1.` What is IPUMS?
`2.` What is ipumsr, and why use it?
.strong[`3.` How to create a data extract]
`4.` Reading data into R
`5.` Exploring and manipulating metadata
`6.` Intro to the IPUMS USA API
`7.` IPUMS API use cases
`8.` Q & A
]
???
Dan passes to Derek. Derek switches to a web demo of extract system.
---
# Overview
.greyed-out[
`1.` What is IPUMS?
`2.` What is ipumsr, and why use it?
`3.` How to create a data extract
.strong[`4.` Reading data into R]
`5.` Exploring and manipulating metadata
`6.` Intro to the IPUMS USA API
`7.` IPUMS API use cases
`8.` Q & A
]
???
Website demo ends, back to slides. Derek passes to Kara.
---
# Downloading your data extract
```{r echo=FALSE, fig.alt="Screenshot of IPUMS data download page with overlaid instructions: 1. Click the 'Download .DAT' link to download the data. 2. Right click the 'DDI' link. 3. In the right-click menu, choose 'Save link as' in Firefox or Chrome, or 'Download Linked File' in Safari."}
knitr::include_graphics("images/microdata_annotated_screenshot.png")
```
--
- You must download both the data and DDI codebook
- Save both files in the same folder
???
Kind of confusing how to save the DDI/.xml file. THIS IS HOW.
DDI is EXTREMELY important, as it contains all the instructions regarding the METADATA
Once your extract is complete, download the data file and the DDI. Downloading
the DDI is a little bit different depending on your browser. On most browsers
you should right-click the file and select “Save As…”. If this saves a file with
a .xml file extension, then you should be ready. However, Safari users must
select “Download Linked File” instead of “Download Linked File As”. On Safari,
selecting the wrong version of these two will download a file with a .html file
extension instead of a .xml extension.
In case anyone was curious, DDI stands for "Data Documentation Initiative" --
the DDI project sets standards for documenting datasets, and the codebooks for
most IPUMS projects follow this standard.
Make sure to save the data and DDI files in the same location.
---
# Downloading your data extract
- Optional: "R" link contains code to read in your data with ipumsr
```{r echo=FALSE, fig.alt="Screenshot of IPUMS data download page with the 'R' link highlighted"}
knitr::include_graphics("images/download_screenshot_2.png")
```
???
The links under "Command Files" contain program-specific code for reading in the
data. The R one contains the code we'll show on the next slide.
This helper code checks that you have ipumsr installed, and if you do, it reads
in the DDI codebook and data into separate objects.
---
# Read in the data
```{r include=FALSE}
if (!file.exists("prcs_migration_extract.xml")) {
# Load extract definition from JSON
prcs_migration_extract <- define_extract_from_json(
"prcs_migration_extract.json",
"usa"
)
# Submit, wait for, and download extract
ddi_filename <- submit_extract(prcs_migration_extract) %>%
wait_for_extract() %>%
download_extract() %>%
basename()
# Infer data file name from DDI file name
data_filename <- str_replace(ddi_filename, "\\.xml$", ".dat.gz")
# Standardize DDI and data file names
file.rename(ddi_filename, "prcs_migration_extract.xml")
file.rename(data_filename, "prcs_migration_extract.dat.gz")
}
ddi <- read_ipums_ddi("prcs_migration_extract.xml")
data <- read_ipums_micro(ddi, data_file = "prcs_migration_extract.dat.gz")
```
- Using functions `read_ipums_ddi()` and `read_ipums_micro()`
```{r eval=FALSE}
ddi <- read_ipums_ddi("usa_00013.xml")
data <- read_ipums_micro(ddi)
```
- Note: supply the codebook, *not* the data file, to `read_ipums_micro()`
???
So you've downloaded both the data and the DDI codebook, and saved them in the
same folder. Here's how you actually read the data into R.
The first option, and the one I'd recommend, is to read the DDI codebook into an
object named "ddi" using the `read_ipums_ddi()` function, and then supply that
ddi object to `read_ipums_micro()`.