Skip to content

Instantly share code, notes, and snippets.

@esjewett
Last active September 23, 2024 04:29
Show Gist options
  • Save esjewett/db2233480b4cd5a15c0bf1cd15ec5f99 to your computer and use it in GitHub Desktop.
Save esjewett/db2233480b4cd5a15c0bf1cd15ec5f99 to your computer and use it in GitHub Desktop.
Generating a visualization of migration of those under 40, by age, state, and whether or not they have a college degree (as opposed to less or more education) - Data citation: IPUMS-USA, University of Minnesota, www.ipums.org.
df_full <- read.csv("~/git_repos/mig_analysis/usa_00006.csv", header=T)
# At what age to people migrate to/from each state?
age_state_of_migrate_to <- filter(df_full, MIGPLAC1 != 0 & MIGPLAC1 <= 56) %>%
mutate(edu = EDUCD == 101) %>%
group_by(AGE, STATEFIP, edu) %>%
summarise(to_count = n())
age_state_of_migrate_from <- filter(df_full, MIGPLAC1 != 0 & MIGPLAC1 <= 56) %>%
mutate(edu = EDUCD == 101) %>%
group_by(AGE, MIGPLAC1, edu) %>%
summarise(from_count = n()) %>%
rename(STATEFIP = MIGPLAC1)
age_state_total_migrate <- filter(df_full) %>%
group_by(AGE, STATEFIP) %>%
summarise(total_count = n())
age_state_of_migrate <- filter(df_full) %>%
mutate(edu = EDUCD == 101) %>%
group_by(AGE, STATEFIP, edu) %>%
summarise(count = n()) %>%
left_join(age_state_total_migrate) %>%
left_join(age_state_of_migrate_to) %>%
left_join(age_state_of_migrate_from) %>%
filter(AGE!=0) %>%
rename(fips = STATEFIP) %>%
left_join(fips_lookup) %>%
mutate(
new_abb = as.character(abb)
) %>%
complete(fips, AGE, edu, fill = list(to_count = 0, from_count = 0, total_count = 0)) %>%
arrange(fips, AGE, edu)
ggplot(data=age_state_of_migrate, aes(fill=edu)) +
geom_bar(stat="sum", aes(x=AGE, y=to_count/total_count), position = "stack") +
geom_bar(stat="sum", aes(x=AGE, y=-from_count/total_count), position = "stack") +
xlab("Age") +
ylab("Migration rate to/from") +
scale_fill_discrete("Education",
labels=c("Lower or higher\nthan college degree\n(EDUCD<>101)", "College Degree")) +
facet_wrap(~new_abb) +
guides(size = F)
ggplot(data=age_state_of_migrate, aes(fill=edu)) +
geom_bar(stat="sum", aes(x=AGE, y=(to_count-from_count)/total_count), position = "stack") +
xlab("Age") +
ylab("Net migration rate") +
scale_fill_discrete("Education",
labels=c("Lower or higher\nthan college degree\n(EDUCD<>101)", "College Degree")) +
facet_wrap(~new_abb) +
guides(size = F)
Description: Revision of (Revision of (Revision of (Revision of (Recreating Upshot analysis here: http://www.nytimes.com/2016/11/22/upshot/the-states-that-college-graduates-are-most-likely-to-leave.html?smid=tw-upshotnyt&smtyp=cur))))
Samples selected:
2000 ACS
Note:
Density of the full data file: 0.13%
Density of your extract: 0.13%
2001 ACS
Note:
Density of the full data file: 0.43%
Density of your extract: 0.43%
2002 ACS
Note:
Density of the full data file: 0.38%
Density of your extract: 0.38%
2003 ACS
Note:
Density of the full data file: 0.42%
Density of your extract: 0.42%
2004 ACS
Note:
Density of the full data file: 0.42%
Density of your extract: 0.42%
2005 ACS
Note:
Density of the full data file: 1.0%
Density of your extract: 1.0%
2006 ACS
Note:
Density of the full data file: 1.0%
Density of your extract: 1.0%
2007 ACS
Note:
Density of the full data file: 1.0%
Density of your extract: 1.0%
2008 ACS
Note:
Density of the full data file: 1.0%
Density of your extract: 1.0%
2009 ACS
Note:
Density of the full data file: 1.0%
Density of your extract: 1.0%
2010 ACS
Note:
Density of the full data file: 1.0%
Density of your extract: 1.0%
2011 ACS
Note:
Density of the full data file: 1.0%
Density of your extract: 1.0%
2012 ACS
Note:
Density of the full data file: 1.0%
Density of your extract: 1.0%
2013 ACS
Note:
Density of the full data file: 1.0%
Density of your extract: 1.0%
2014 ACS
Note:
Density of the full data file: 1.0%
Density of your extract: 1.0%
2015 ACS
Note:
Density of the full data file: 1.0%
Density of your extract: 1.0%
File Type: rectangular
Case Selection: Yes
Variable Columns Len 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015
YEAR H 1-4 4 X X X X X X X X X X X X X X X X
STATEFIP H 5-6 2 X X X X X X X X X X X X X X X X
AGE P 7-9 3 X X X X X X X X X X X X X X X X
EDUC P 10-11 2 X X X X X X X X X X X X X X X X
EDUCD P 12-14 3 X X X X X X X X X X X X X X X X
MIGPLAC1 P 15-17 3 X X X X X X X X X X X X X X X X
Variable Availability Key:
All Years X - available in this sample
All Years . - not available in this sample
Case Selections:
P AGE 000 Less than 1 year old
P AGE 001 1
P AGE 002 2
P AGE 003 3
P AGE 004 4
P AGE 005 5
P AGE 006 6
P AGE 007 7
P AGE 008 8
P AGE 009 9
P AGE 010 10
P AGE 011 11
P AGE 012 12
P AGE 013 13
P AGE 014 14
P AGE 015 15
P AGE 016 16
P AGE 017 17
P AGE 018 18
P AGE 019 19
P AGE 020 20
P AGE 021 21
P AGE 022 22
P AGE 023 23
P AGE 024 24
P AGE 025 25
P AGE 026 26
P AGE 027 27
P AGE 028 28
P AGE 029 29
P AGE 030 30
P AGE 031 31
P AGE 032 32
P AGE 033 33
P AGE 034 34
P AGE 035 35
P AGE 036 36
P AGE 037 37
P AGE 038 38
P AGE 039 39
P AGE 040 40
YEAR Census year
1850 1850
1860 1860
1870 1870
1880 1880
1900 1900
1910 1910
1920 1920
1930 1930
1940 1940
1950 1950
1960 1960
1970 1970
1980 1980
1990 1990
2000 2000
2001 2001
2002 2002
2003 2003
2004 2004
2005 2005
2006 2006
2007 2007
2008 2008
2009 2009
2010 2010
2011 2011
2012 2012
2013 2013
2014 2014
2015 2015
STATEFIP State (FIPS code)
01 Alabama
02 Alaska
04 Arizona
05 Arkansas
06 California
08 Colorado
09 Connecticut
10 Delaware
11 District of Columbia
12 Florida
13 Georgia
15 Hawaii
16 Idaho
17 Illinois
18 Indiana
19 Iowa
20 Kansas
21 Kentucky
22 Louisiana
23 Maine
24 Maryland
25 Massachusetts
26 Michigan
27 Minnesota
28 Mississippi
29 Missouri
30 Montana
31 Nebraska
32 Nevada
33 New Hampshire
34 New Jersey
35 New Mexico
36 New York
37 North Carolina
38 North Dakota
39 Ohio
40 Oklahoma
41 Oregon
42 Pennsylvania
44 Rhode Island
45 South Carolina
46 South Dakota
47 Tennessee
48 Texas
49 Utah
50 Vermont
51 Virginia
53 Washington
54 West Virginia
55 Wisconsin
56 Wyoming
State groups (1980 Urban/rural sample):
61 Maine-New Hampshire-Vermont
62 Massachusetts-Rhode Island
63 Minnesota-Iowa-Missouri-Kansas-Nebraska-S.Dakota-N.Dakota
64 Maryland-Delaware
65 Montana-Idaho-Wyoming
66 Utah-Nevada
67 Arizona-New Mexico
68 Alaska-Hawaii
72 Puerto Rico
97 Military/Mil. Reservation
99 State not identified
AGE Age
000 Less than 1 year old
001 1
002 2
003 3
004 4
005 5
006 6
007 7
008 8
009 9
010 10
011 11
012 12
013 13
014 14
015 15
016 16
017 17
018 18
019 19
020 20
021 21
022 22
023 23
024 24
025 25
026 26
027 27
028 28
029 29
030 30
031 31
032 32
033 33
034 34
035 35
036 36
037 37
038 38
039 39
040 40
041 41
042 42
043 43
044 44
045 45
046 46
047 47
048 48
049 49
050 50
051 51
052 52
053 53
054 54
055 55
056 56
057 57
058 58
059 59
060 60
061 61
062 62
063 63
064 64
065 65
066 66
067 67
068 68
069 69
070 70
071 71
072 72
073 73
074 74
075 75
076 76
077 77
078 78
079 79
080 80
081 81
082 82
083 83
084 84
085 85
086 86
087 87
088 88
089 89
090 90 (90+ in 1980 and 1990)
091 91
092 92
093 93
094 94
095 95
096 96
097 97
098 98
099 99
100 100 (100+ in 1960-1970)
101 101
102 102
103 103
104 104
105 105
106 106
107 107
108 108
109 109
110 110
111 111
112 112 (112+ in the 1980 internal data)
113 113
114 114
115 115 (115+ in the 1990 internal data)
116 116
117 117
118 118
119 119
120 120
121 121
122 122
123 123
124 124
125 125
126 126
129 129
130 130
135 135
EDUC Educational attainment [general version]
00 N/A or no schooling
01 Nursery school to grade 4
02 Grade 5, 6, 7, or 8
03 Grade 9
04 Grade 10
05 Grade 11
06 Grade 12
07 1 year of college
08 2 years of college
09 3 years of college
10 4 years of college
11 5+ years of college
EDUCD Educational attainment [detailed version]
000 N/A or no schooling
001 N/A
002 No schooling completed
010 Nursery school to grade 4
011 Nursery school, preschool
012 Kindergarten
013 Grade 1, 2, 3, or 4
014 Grade 1
015 Grade 2
016 Grade 3
017 Grade 4
020 Grade 5, 6, 7, or 8
021 Grade 5 or 6
022 Grade 5
023 Grade 6
024 Grade 7 or 8
025 Grade 7
026 Grade 8
030 Grade 9
040 Grade 10
050 Grade 11
060 Grade 12
061 12th grade, no diploma
062 High school graduate or GED
063 Regular high school diploma
064 GED or alternative credential
065 Some college, but less than 1 year
070 1 year of college
071 1 or more years of college credit, no degree
080 2 years of college
081 Associate's degree, type not specified
082 Associate's degree, occupational program
083 Associate's degree, academic program
090 3 years of college
100 4 years of college
101 Bachelor's degree
110 5+ years of college
111 6 years of college (6+ in 1960-1970)
112 7 years of college
113 8+ years of college
114 Master's degree
115 Professional degree beyond a bachelor's degree
116 Doctoral degree
999 Missing
MIGPLAC1 State or country of residence 1 year ago
000 N/A
001 Alabama
002 Alaska
004 Arizona
005 Arkansas
006 California
008 Colorado
009 Connecticut
010 Delaware
011 District of Columbia
012 Florida
013 Georgia
015 Hawaii
016 Idaho
017 Illinois
018 Indiana
019 Iowa
020 Kansas
021 Kentucky
022 Louisiana
023 Maine
024 Maryland
025 Massachusetts
026 Michigan
027 Minnesota
028 Mississippi
029 Missouri
030 Montana
031 Nebraska
032 Nevada
033 New Hampshire
034 New Jersey
035 New Mexico
036 New York
037 North Carolina
038 North Dakota
039 Ohio
040 Oklahoma
041 Oregon
042 Pennsylvania
044 Rhode Island
045 South Carolina
046 South Dakota
047 Tennessee
048 Texas
049 Utah
050 Vermont
051 Virginia
053 Washington
054 West Virginia
055 Wisconsin
056 Wyoming
099 United States, ns
100 Samoa, 1950
105 Guam
110 Puerto Rico
115 Virgin Islands
120 Other US Possessions
150 Canada
151 English Canada
152 French Canada
160 Atlantic Islands
200 Mexico
211 Belize/British Honduras
212 Costa Rica
213 El Salvador
214 Guatemala
215 Honduras
216 Nicaragua
217 Panama
218 Canal Zone
219 Central America, nec
250 Cuba
261 Dominican Republic
262 Haita
263 Jamaica
264 British West Indies
267 Other West Indies
290 Other Caribbean and North America
305 Argentina
310 Bolivia
315 Brazil
320 Chile
325 Colombia
330 Ecuador
345 Paraguay
350 Peru
360 Uruguay
365 Venezuela
390 South America, nec
400 Denmark
401 Finland
402 Iceland
404 Norway
405 Sweden
410 England
411 Scotland
412 Wales
413 United Kingdom (excluding England: 2005ACS)
414 Ireland
415 Northern Ireland
419 Other Northern Europe
420 Belgium
421 France
422 Luxembourg
425 Netherlands
426 Switzerland
429 Other Western Europe
430 Albania
433 Greece
434 Dodecanese Islands
435 Italy
436 Portugal
437 Azores
438 Spain
450 Austria
451 Bulgaria
452 Czechoslovakia
453 Germany
454 Hungary
455 Poland
456 Romania
457 Yugoslavia
458 Bosnia and Herzegovinia
459 Other Eastern Europe
460 Estonia
461 Latvia
462 Lithuania
463 Other Northern or Eastern Europe
465 USSR
498 Ukraine
499 Europe, ns
500 China
501 Japan
502 Korea
503 Taiwan
515 Philippines
517 Thailand
518 Vietnam
519 Other South East Asia
520 Nepal
521 India
522 Iran
523 Iraq
525 Pakistan
534 Israel/Palestine
535 Jordan
537 Lebanon
540 Saudi Arabia
541 Syria
542 Turkey
543 Afghanistan
551 Other Western Asia
599 Asia, nec
600 Africa
610 Northern Africa
611 Egypt
619 Nigeria
620 Western Africa
621 Eastern Africa
694 South Africa (Union of)
699 Africa, nec
701 Australia
702 New Zealand
710 Pacific Islands (Australia and New Zealand Subregions, not specified, Oceania and at Sea: ACS)
900 Abroad (unknown) or at sea
997 Unknown value
999 Missing
@Enambriat1996
Copy link

I visited your site and I like to say that These services offer personalized, well-researched content tailored to specific requirements. By working with professional writers, students gain valuable insights into structuring arguments, presenting ideas logically, and maintaining an academic tone. Beyond simply completing the assignment, using such services can be an educational tool, helping improve writing skills over time Please click here academized.com/write-my-essay it’s crucial to choose reputable providers who emphasize originality and adhere to academic integrity. With the right support, students can manage their workload more effectively while also enhancing their writing proficiency. Just remember, it's a learning aid, not a shortcut to avoid effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment