In the wake of the Great Recession of 2009, there has been a good deal of focus on employment statistics, one of the most important metrics policymakers use to gauge the overall strength of the economy. In the United States, the government measures unemployment using the Current Population Survey (CPS), which collects demographic and employment information from a wide range of Americans each month. In this exercise, we will employ the topics reviewed in the lectures as well as a few new techniques using the September 2013 version of this rich, nationally representative dataset (available online).
The observations in the dataset represent people surveyed in the September 2013 CPS who actually completed a survey. While the full dataset has 385 variables, in this exercise we will use a more compact version of the dataset, CPSData.csv, which has the following variables:
PeopleInHousehold: The number of people in the interviewee’s household.
Region: The census region where the interviewee lives.
State: The state where the interviewee lives.
MetroAreaCode: A code that identifies the metropolitan area in which the interviewee lives (missing if the interviewee does not live in a metropolitan area). The mapping from codes to names of metropolitan areas is provided in the file MetroAreaCodes.csv.
Age: The age, in years, of the interviewee. 80 represents people aged 80-84, and 85 represents people aged 85 and higher.
Married: The marriage status of the interviewee.
Sex: The sex of the interviewee.
Education: The maximum level of education obtained by the interviewee.
Race: The race of the interviewee.
Hispanic: Whether the interviewee is of Hispanic ethnicity.
CountryOfBirthCode: A code identifying the country of birth of the interviewee. The mapping from codes to names of countries is provided in the file CountryCodes.csv.
Citizenship: The United States citizenship status of the interviewee.
EmploymentStatus: The status of employment of the interviewee.
Industry: The industry of employment of the interviewee (only available if they are employed).
Load the dataset from CPSData.csv into a data frame called CPS, and view the dataset with the summary() and str() commands.How many interviewees are in the dataset?
CPS=read.csv("data/CPSData.csv")
summary(CPS)
PeopleInHousehold Region State MetroAreaCode Age Married Sex
Min. : 1.000 Midwest :30684 California :11570 Min. :10420 Min. : 0.00 Divorced :11151 Female:67481
1st Qu.: 2.000 Northeast:25939 Texas : 7077 1st Qu.:21780 1st Qu.:19.00 Married :55509 Male :63821
Median : 3.000 South :41502 New York : 5595 Median :34740 Median :39.00 Never Married:30772
Mean : 3.284 West :33177 Florida : 5149 Mean :35075 Mean :38.83 Separated : 2027
3rd Qu.: 4.000 Pennsylvania: 3930 3rd Qu.:41860 3rd Qu.:57.00 Widowed : 6505
Max. :15.000 Illinois : 3912 Max. :79600 Max. :85.00 NA's :25338
(Other) :94069 NA's :34238
Education Race Hispanic CountryOfBirthCode Citizenship
High school :30906 American Indian : 1433 Min. :0.0000 Min. : 57.00 Citizen, Native :116639
Bachelor's degree :19443 Asian : 6520 1st Qu.:0.0000 1st Qu.: 57.00 Citizen, Naturalized: 7073
Some college, no degree:18863 Black : 13913 Median :0.0000 Median : 57.00 Non-Citizen : 7590
No high school diploma :16095 Multiracial : 2897 Mean :0.1393 Mean : 82.68
Associate degree : 9913 Pacific Islander: 618 3rd Qu.:0.0000 3rd Qu.: 57.00
(Other) :10744 White :105921 Max. :1.0000 Max. :555.00
NA's :25338
EmploymentStatus Industry
Disabled : 5712 Educational and health services :15017
Employed :61733 Trade : 8933
Not in Labor Force:15246 Professional and business services: 7519
Retired :18619 Manufacturing : 6791
Unemployed : 4203 Leisure and hospitality : 6364
NA's :25789 (Other) :21618
NA's :65060
str(CPS)
'data.frame': 131302 obs. of 14 variables:
$ PeopleInHousehold : int 1 3 3 3 3 3 3 2 2 2 ...
$ Region : Factor w/ 4 levels "Midwest","Northeast",..: 3 3 3 3 3 3 3 3 3 3 ...
$ State : Factor w/ 51 levels "Alabama","Alaska",..: 1 1 1 1 1 1 1 1 1 1 ...
$ MetroAreaCode : int 26620 13820 13820 13820 26620 26620 26620 33660 33660 26620 ...
$ Age : int 85 21 37 18 52 24 26 71 43 52 ...
$ Married : Factor w/ 5 levels "Divorced","Married",..: 5 3 3 3 5 3 3 1 1 3 ...
$ Sex : Factor w/ 2 levels "Female","Male": 1 2 1 2 1 2 2 1 2 2 ...
$ Education : Factor w/ 8 levels "Associate degree",..: 1 4 4 6 1 2 4 4 4 2 ...
$ Race : Factor w/ 6 levels "American Indian",..: 6 3 3 3 6 6 6 6 6 6 ...
$ Hispanic : int 0 0 0 0 0 0 0 0 0 0 ...
$ CountryOfBirthCode: int 57 57 57 57 57 57 57 57 57 57 ...
$ Citizenship : Factor w/ 3 levels "Citizen, Native",..: 1 1 1 1 1 1 1 1 1 1 ...
$ EmploymentStatus : Factor w/ 5 levels "Disabled","Employed",..: 4 5 1 3 2 2 2 2 3 2 ...
$ Industry : Factor w/ 14 levels "Agriculture, forestry, fishing, and hunting",..: NA 11 NA NA 11 4 14 4 NA 12 ...
nrow(CPS)
[1] 131302
Among the interviewees with a value reported for the Industry variable, what is the most common industry of employment? Please enter the name exactly how you see it.
sort(table(CPS$Industry),TRUE)
Educational and health services Trade Professional and business services
15017 8933 7519
Manufacturing Leisure and hospitality Construction
6791 6364 4387
Financial Transportation and utilities Other services
4347 3260 3224
Public administration Information Agriculture, forestry, fishing, and hunting
3186 1328 1307
Mining Armed forces
550 29
#Educational and health services
Recall from the homework assignment “The Analytical Detective” that you can call the sort() function on the output of the table() function to obtain a sorted breakdown of a variable. For instance, sort(table(CPS$Region)) sorts the regions by the number of interviewees from that region.
Which state has the fewest interviewees?
sort(table(CPS$State),FALSE)
New Mexico Montana Mississippi Alabama West Virginia Arkansas
1102 1214 1230 1376 1409 1421
Louisiana Idaho Oklahoma Arizona Alaska Wyoming
1450 1518 1523 1528 1590 1624
North Dakota South Carolina Tennessee District of Columbia Kentucky Utah
1645 1658 1784 1791 1841 1842
Nevada Vermont Kansas Oregon Nebraska Massachusetts
1856 1890 1935 1943 1949 1987
South Dakota Indiana Hawaii Missouri Rhode Island Delaware
2000 2004 2099 2145 2209 2214
Maine Washington Iowa New Jersey North Carolina New Hampshire
2263 2366 2528 2567 2619 2662
Wisconsin Georgia Connecticut Colorado Virginia Michigan
2686 2807 2836 2925 2953 3063
Minnesota Maryland Ohio Illinois Pennsylvania Florida
3139 3200 3678 3912 3930 5149
New York Texas California
5595 7077 11570
#New Mexico
Which state has the largest number of interviewees?
sort(table(CPS$State),TRUE)
California Texas New York Florida Pennsylvania Illinois
11570 7077 5595 5149 3930 3912
Ohio Maryland Minnesota Michigan Virginia Colorado
3678 3200 3139 3063 2953 2925
Connecticut Georgia Wisconsin New Hampshire North Carolina New Jersey
2836 2807 2686 2662 2619 2567
Iowa Washington Maine Delaware Rhode Island Missouri
2528 2366 2263 2214 2209 2145
Hawaii Indiana South Dakota Massachusetts Nebraska Oregon
2099 2004 2000 1987 1949 1943
Kansas Vermont Nevada Utah Kentucky District of Columbia
1935 1890 1856 1842 1841 1791
Tennessee South Carolina North Dakota Wyoming Alaska Arizona
1784 1658 1645 1624 1590 1528
Oklahoma Idaho Louisiana Arkansas West Virginia Alabama
1523 1518 1450 1421 1409 1376
Mississippi Montana New Mexico
1230 1214 1102
#California
What proportion of interviewees are citizens of the United States?
levels(CPS$Citizenship)
[1] "Citizen, Native" "Citizen, Naturalized" "Non-Citizen"
nrow(subset(CPS,Citizenship=="Citizen, Native"|Citizenship=="Citizen, Naturalized"))/nrow(CPS)
[1] 0.9421943
The CPS differentiates between race (with possible values American Indian, Asian, Black, Pacific Islander, White, or Multiracial) and ethnicity. A number of interviewees are of Hispanic ethnicity, as captured by the Hispanic variable. For which races are there at least 250 interviewees in the CPS dataset of Hispanic ethnicity? (Select all that apply.)
table(CPS$Race,CPS$Hispanic)>250
0 1
American Indian TRUE TRUE
Asian TRUE FALSE
Black TRUE TRUE
Multiracial TRUE TRUE
Pacific Islander TRUE FALSE
White TRUE TRUE
#American Indian,Black,Multiracial,White
Which variables have at least one interviewee with a missing (NA) value? (Select all that apply.)
summary(CPS)
PeopleInHousehold Region State MetroAreaCode Age Married Sex
Min. : 1.000 Midwest :30684 California :11570 Min. :10420 Min. : 0.00 Divorced :11151 Female:67481
1st Qu.: 2.000 Northeast:25939 Texas : 7077 1st Qu.:21780 1st Qu.:19.00 Married :55509 Male :63821
Median : 3.000 South :41502 New York : 5595 Median :34740 Median :39.00 Never Married:30772
Mean : 3.284 West :33177 Florida : 5149 Mean :35075 Mean :38.83 Separated : 2027
3rd Qu.: 4.000 Pennsylvania: 3930 3rd Qu.:41860 3rd Qu.:57.00 Widowed : 6505
Max. :15.000 Illinois : 3912 Max. :79600 Max. :85.00 NA's :25338
(Other) :94069 NA's :34238
Education Race Hispanic CountryOfBirthCode Citizenship
High school :30906 American Indian : 1433 Min. :0.0000 Min. : 57.00 Citizen, Native :116639
Bachelor's degree :19443 Asian : 6520 1st Qu.:0.0000 1st Qu.: 57.00 Citizen, Naturalized: 7073
Some college, no degree:18863 Black : 13913 Median :0.0000 Median : 57.00 Non-Citizen : 7590
No high school diploma :16095 Multiracial : 2897 Mean :0.1393 Mean : 82.68
Associate degree : 9913 Pacific Islander: 618 3rd Qu.:0.0000 3rd Qu.: 57.00
(Other) :10744 White :105921 Max. :1.0000 Max. :555.00
NA's :25338
EmploymentStatus Industry
Disabled : 5712 Educational and health services :15017
Employed :61733 Trade : 8933
Not in Labor Force:15246 Professional and business services: 7519
Retired :18619 Manufacturing : 6791
Unemployed : 4203 Leisure and hospitality : 6364
NA's :25789 (Other) :21618
NA's :65060
#MetroAreaCode,Married,Education,EmploymentStatus,Industry
Often when evaluating a new dataset, we try to identify if there is a pattern in the missing values in the dataset. We will try to determine if there is a pattern in the missing values of the Married variable. The function
is.na(CPS$Married)
returns a vector of TRUE/FALSE values for whether the Married variable is missing. We can see the breakdown of whether Married is missing based on the reported value of the Region variable with the function
table(CPS$Region, is.na(CPS$Married))
Which is the most accurate:
table(CPS$Region, is.na(CPS$Married))
FALSE TRUE
Midwest 24609 6075
Northeast 21432 4507
South 33535 7967
West 26388 6789
table(CPS$Sex, is.na(CPS$Married))
FALSE TRUE
Female 55264 12217
Male 50700 13121
table(CPS$Age, is.na(CPS$Married))
FALSE TRUE
0 0 1283
1 0 1559
2 0 1574
3 0 1693
4 0 1695
5 0 1795
6 0 1721
7 0 1681
8 0 1729
9 0 1748
10 0 1750
11 0 1721
12 0 1797
13 0 1802
14 0 1790
15 1795 0
16 1751 0
17 1764 0
18 1596 0
19 1517 0
20 1398 0
21 1525 0
22 1536 0
23 1638 0
24 1627 0
25 1604 0
26 1643 0
27 1657 0
28 1736 0
29 1645 0
30 1854 0
31 1762 0
32 1790 0
33 1804 0
34 1653 0
35 1716 0
36 1663 0
37 1531 0
38 1530 0
39 1542 0
40 1571 0
41 1673 0
42 1711 0
43 1819 0
44 1764 0
45 1749 0
46 1665 0
47 1647 0
48 1791 0
49 1989 0
50 1966 0
51 1931 0
52 1935 0
53 1994 0
54 1912 0
55 1895 0
56 1935 0
57 1827 0
58 1874 0
59 1758 0
60 1746 0
61 1735 0
62 1595 0
63 1596 0
64 1519 0
65 1569 0
66 1577 0
67 1227 0
68 1130 0
69 1062 0
70 1195 0
71 1031 0
72 941 0
73 896 0
74 842 0
75 763 0
76 729 0
77 698 0
78 659 0
79 661 0
80 2664 0
85 2446 0
table(CPS$Citizenship, is.na(CPS$Married))
FALSE TRUE
Citizen, Native 91956 24683
Citizen, Naturalized 6910 163
Non-Citizen 7098 492
#The Married variable being missing is related to the Age value for the interviewee.
As mentioned in the variable descriptions, MetroAreaCode is missing if an interviewee does not live in a metropolitan area. Using the same technique as in the previous question, answer the following questions about people who live in non-metropolitan areas.
How many states had all interviewees living in a non-metropolitan area (aka they have a missing MetroAreaCode value)? For this question, treat the District of Columbia as a state (even though it is not technically a state).
table(CPS$State,is.na(CPS$MetroAreaCode))
FALSE TRUE
Alabama 1020 356
Alaska 0 1590
Arizona 1327 201
Arkansas 724 697
California 11333 237
Colorado 2545 380
Connecticut 2593 243
Delaware 1696 518
District of Columbia 1791 0
Florida 4947 202
Georgia 2250 557
Hawaii 1576 523
Idaho 761 757
Illinois 3473 439
Indiana 1420 584
Iowa 1297 1231
Kansas 1234 701
Kentucky 908 933
Louisiana 1216 234
Maine 909 1354
Maryland 2978 222
Massachusetts 1858 129
Michigan 2517 546
Minnesota 2150 989
Mississippi 376 854
Missouri 1440 705
Montana 199 1015
Nebraska 816 1133
Nevada 1609 247
New Hampshire 1148 1514
New Jersey 2567 0
New Mexico 832 270
New York 5144 451
North Carolina 1642 977
North Dakota 432 1213
Ohio 2754 924
Oklahoma 1024 499
Oregon 1519 424
Pennsylvania 3245 685
Rhode Island 2209 0
South Carolina 1139 519
South Dakota 595 1405
Tennessee 1149 635
Texas 6060 1017
Utah 1455 387
Vermont 657 1233
Virginia 2367 586
Washington 1937 429
West Virginia 344 1065
Wisconsin 1882 804
Wyoming 0 1624
#2
How many states had all interviewees living in a metropolitan area? Again, treat the District of Columbia as a state.
#3
Which region of the United States has the largest proportion of interviewees living in a non-metropolitan area?
table(CPS$Region,is.na(CPS$MetroAreaCode))
FALSE TRUE
Midwest 20010 10674
Northeast 20330 5609
South 31631 9871
West 25093 8084
#Midwest
While we were able to use the table() command to compute the proportion of interviewees from each region not living in a metropolitan area, it was somewhat tedious (it involved manually computing the proportion for each region) and isn’t something you would want to do if there were a larger number of options. It turns out there is a less tedious way to compute the proportion of values that are TRUE. The mean() function, which takes the average of the values passed to it, will treat TRUE as 1 and FALSE as 0, meaning it returns the proportion of values that are true. For instance, mean(c(TRUE, FALSE, TRUE, TRUE)) returns 0.75. Knowing this, use tapply() with the mean function to answer the following questions:
Which state has a proportion of interviewees living in a non-metropolitan area closest to 30%?
sort(abs(tapply(is.na(CPS$MetroAreaCode),CPS$State,mean)-0.3),FALSE)
Wisconsin Indiana South Carolina Minnesota Oklahoma Missouri
0.0006701415 0.0085828343 0.0130277443 0.0150684932 0.0276428102 0.0286713287
Alabama Ohio Hawaii New Mexico Tennessee Kansas
0.0412790698 0.0487765090 0.0508337303 0.0549909256 0.0559417040 0.0622739018
Delaware North Carolina Oregon Utah Virginia Georgia
0.0660343270 0.0730431462 0.0817807514 0.0899022801 0.1015577379 0.1015675098
Washington Michigan Pennsylvania Louisiana Texas Nevada
0.1186813187 0.1217433888 0.1256997455 0.1386206897 0.1562950403 0.1669181034
Arizona Colorado Iowa Illinois Arkansas Idaho
0.1684554974 0.1700854701 0.1869462025 0.1877811861 0.1904996481 0.1986824769
Kentucky Connecticut New York Maryland Massachusetts Florida
0.2067897882 0.2143159379 0.2193923146 0.2306250000 0.2350780070 0.2607690814
New Hampshire California Nebraska Maine District of Columbia New Jersey
0.2687453043 0.2795159896 0.2813237558 0.2983208131 0.3000000000 0.3000000000
Rhode Island Vermont Mississippi South Dakota North Dakota West Virginia
0.3000000000 0.3523809524 0.3943089431 0.4025000000 0.4373860182 0.4558552165
Montana Alaska Wyoming
0.5360790774 0.7000000000 0.7000000000
#Wisconsin
Which state has the largest proportion of non-metropolitan interviewees, ignoring states where all interviewees were non-metropolitan?
sort(tapply(is.na(CPS$MetroAreaCode),CPS$State,mean),TRUE)
Alaska Wyoming Montana West Virginia North Dakota South Dakota
1.00000000 1.00000000 0.83607908 0.75585522 0.73738602 0.70250000
Mississippi Vermont Maine Nebraska New Hampshire Kentucky
0.69430894 0.65238095 0.59832081 0.58132376 0.56874530 0.50678979
Idaho Arkansas Iowa North Carolina Kansas Tennessee
0.49868248 0.49049965 0.48694620 0.37304315 0.36227390 0.35594170
Missouri Oklahoma Minnesota South Carolina Wisconsin Indiana
0.32867133 0.32764281 0.31506849 0.31302774 0.29932986 0.29141717
Alabama Ohio Hawaii New Mexico Delaware Oregon
0.25872093 0.25122349 0.24916627 0.24500907 0.23396567 0.21821925
Utah Virginia Georgia Washington Michigan Pennsylvania
0.21009772 0.19844226 0.19843249 0.18131868 0.17825661 0.17430025
Louisiana Texas Nevada Arizona Colorado Illinois
0.16137931 0.14370496 0.13308190 0.13154450 0.12991453 0.11221881
Connecticut New York Maryland Massachusetts Florida California
0.08568406 0.08060769 0.06937500 0.06492199 0.03923092 0.02048401
District of Columbia New Jersey Rhode Island
0.00000000 0.00000000 0.00000000
# Montana
Codes like MetroAreaCode and CountryOfBirthCode are a compact way to encode factor variables with text as their possible values, and they are therefore quite common in survey datasets. In fact, all but one of the variables in this dataset were actually stored by a numeric code in the original CPS datafile.
When analyzing a variable stored by a numeric code, we will often want to convert it into the values the codes represent. To do this, we will use a dictionary, which maps the the code to the actual value of the variable. We have provided dictionaries MetroAreaCodes.csv and CountryCodes.csv, which respectively map MetroAreaCode and CountryOfBirthCode into their true values. Read these two dictionaries into data frames MetroAreaMap and CountryMap.
How many observations (codes for metropolitan areas) are there in MetroAreaMap?
MetroAreaMap=read.csv("data/MetroAreaCodes.csv")
CountryMap=read.csv("data/CountryCodes.csv")
nrow(M)
[1] 271
How many observations (codes for countries) are there in CountryMap?
nrow(CountryMap)
[1] 149
To merge in the metropolitan areas, we want to connect the field MetroAreaCode from the CPS data frame with the field Code in MetroAreaMap. The following command merges the two data frames on these columns, overwriting the CPS data frame with the result:
CPS = merge(CPS, MetroAreaMap, by.x="MetroAreaCode", by.y="Code", all.x=TRUE)
The first two arguments determine the data frames to be merged (they are called “x” and “y”, respectively, in the subsequent parameters to the merge function). by.x=“MetroAreaCode” means we’re matching on the MetroAreaCode variable from the “x” data frame (CPS), while by.y=“Code” means we’re matching on the Code variable from the “y” data frame (MetroAreaMap). Finally, all.x=TRUE means we want to keep all rows from the “x” data frame (CPS), even if some of the rows’ MetroAreaCode doesn’t match any codes in MetroAreaMap (for those familiar with database terminology, this parameter makes the operation a left outer join instead of an inner join).
Review the new version of the CPS data frame with the summary() and str() functions. What is the name of the variable that was added to the data frame by the merge() operation?
CPS = merge(CPS, MetroAreaMap, by.x="MetroAreaCode", by.y="Code", all.x=TRUE)
summary(CPS)
MetroAreaCode PeopleInHousehold Region State Age Married Sex
Min. :10420 Min. : 1.000 Midwest :30684 California :11570 Min. : 0.00 Divorced :11151 Female:67481
1st Qu.:21780 1st Qu.: 2.000 Northeast:25939 Texas : 7077 1st Qu.:19.00 Married :55509 Male :63821
Median :34740 Median : 3.000 South :41502 New York : 5595 Median :39.00 Never Married:30772
Mean :35075 Mean : 3.284 West :33177 Florida : 5149 Mean :38.83 Separated : 2027
3rd Qu.:41860 3rd Qu.: 4.000 Pennsylvania: 3930 3rd Qu.:57.00 Widowed : 6505
Max. :79600 Max. :15.000 Illinois : 3912 Max. :85.00 NA's :25338
NA's :34238 (Other) :94069
Education Race Hispanic CountryOfBirthCode Citizenship
High school :30906 American Indian : 1433 Min. :0.0000 Min. : 57.00 Citizen, Native :116639
Bachelor's degree :19443 Asian : 6520 1st Qu.:0.0000 1st Qu.: 57.00 Citizen, Naturalized: 7073
Some college, no degree:18863 Black : 13913 Median :0.0000 Median : 57.00 Non-Citizen : 7590
No high school diploma :16095 Multiracial : 2897 Mean :0.1393 Mean : 82.68
Associate degree : 9913 Pacific Islander: 618 3rd Qu.:0.0000 3rd Qu.: 57.00
(Other) :10744 White :105921 Max. :1.0000 Max. :555.00
NA's :25338
EmploymentStatus Industry MetroArea
Disabled : 5712 Educational and health services :15017 New York-Northern New Jersey-Long Island, NY-NJ-PA: 5409
Employed :61733 Trade : 8933 Washington-Arlington-Alexandria, DC-VA-MD-WV : 4177
Not in Labor Force:15246 Professional and business services: 7519 Los Angeles-Long Beach-Santa Ana, CA : 4102
Retired :18619 Manufacturing : 6791 Philadelphia-Camden-Wilmington, PA-NJ-DE : 2855
Unemployed : 4203 Leisure and hospitality : 6364 Chicago-Naperville-Joliet, IN-IN-WI : 2772
NA's :25789 (Other) :21618 (Other) :77749
NA's :65060 NA's :34238
str(CPS)
'data.frame': 131302 obs. of 15 variables:
$ MetroAreaCode : int 10420 10420 10420 10420 10420 10420 10420 10420 10420 10420 ...
$ PeopleInHousehold : int 4 4 2 4 1 3 4 4 2 3 ...
$ Region : Factor w/ 4 levels "Midwest","Northeast",..: 1 1 1 1 1 1 1 1 1 1 ...
$ State : Factor w/ 51 levels "Alabama","Alaska",..: 36 36 36 36 36 36 36 36 36 36 ...
$ Age : int 2 9 73 40 63 19 30 6 60 32 ...
$ Married : Factor w/ 5 levels "Divorced","Married",..: NA NA 2 2 3 3 2 NA 2 2 ...
$ Sex : Factor w/ 2 levels "Female","Male": 2 2 1 1 2 1 1 1 1 2 ...
$ Education : Factor w/ 8 levels "Associate degree",..: NA NA 8 4 6 4 2 NA 4 4 ...
$ Race : Factor w/ 6 levels "American Indian",..: 6 6 6 6 6 6 2 6 6 6 ...
$ Hispanic : int 0 0 0 0 0 0 0 1 0 0 ...
$ CountryOfBirthCode: int 57 57 57 362 57 57 203 57 57 57 ...
$ Citizenship : Factor w/ 3 levels "Citizen, Native",..: 1 1 1 2 1 1 3 1 1 1 ...
$ EmploymentStatus : Factor w/ 5 levels "Disabled","Employed",..: NA NA 4 3 1 2 3 NA 2 2 ...
$ Industry : Factor w/ 14 levels "Agriculture, forestry, fishing, and hunting",..: NA NA NA NA NA 7 NA NA 4 13 ...
$ MetroArea : Factor w/ 271 levels "Akron, OH","Albany, GA",..: 1 1 1 1 1 1 1 1 1 1 ...
#MetroArea
How many interviewees have a missing value for the new metropolitan area variable? Note that all of these interviewees would have been removed from the merged data frame if we did not include the all.x=TRUE parameter.
sum(is.na(CPS$MetroArea))
[1] 34238
Which of the following metropolitan areas has the largest number of interviewees?
sort(table(CPS$MetroArea),TRUE)
New York-Northern New Jersey-Long Island, NY-NJ-PA Washington-Arlington-Alexandria, DC-VA-MD-WV
5409 4177
Los Angeles-Long Beach-Santa Ana, CA Philadelphia-Camden-Wilmington, PA-NJ-DE
4102 2855
Chicago-Naperville-Joliet, IN-IN-WI Providence-Fall River-Warwick, MA-RI
2772 2284
Boston-Cambridge-Quincy, MA-NH Minneapolis-St Paul-Bloomington, MN-WI
2229 1942
Dallas-Fort Worth-Arlington, TX Houston-Baytown-Sugar Land, TX
1863 1649
Honolulu, HI Miami-Fort Lauderdale-Miami Beach, FL
1576 1554
Atlanta-Sandy Springs-Marietta, GA Denver-Aurora, CO
1552 1504
Baltimore-Towson, MD San Francisco-Oakland-Fremont, CA
1483 1386
Detroit-Warren-Livonia, MI Las Vegas-Paradise, NV
1354 1299
Riverside-San Bernardino, CA Seattle-Tacoma-Bellevue, WA
1290 1255
Portland-Vancouver-Beaverton, OR-WA Phoenix-Mesa-Scottsdale, AZ
1089 971
Kansas City, MO-KS Omaha-Council Bluffs, NE-IA
962 957
St. Louis, MO-IL San Diego-Carlsbad-San Marcos, CA
956 907
Hartford-West Hartford-East Hartford, CT Tampa-St. Petersburg-Clearwater, FL
885 842
Pittsburgh, PA Bridgeport-Stamford-Norwalk, CT
732 730
Salt Lake City, UT Cincinnati-Middletown, OH-KY-IN
723 719
Milwaukee-Waukesha-West Allis, WI Portland-South Portland, ME
714 701
Cleveland-Elyria-Mentor, OH San Jose-Sunnyvale-Santa Clara, CA
681 670
Sacramento-Arden-Arcade-Roseville, CA Burlington-South Burlington, VT
667 657
Boise City-Nampa, ID Orlando, FL
644 610
Albuquerque, NM San Antonio, TX
609 607
Oklahoma City, OK Virginia Beach-Norfolk-Newport News, VA-NC
604 597
Sioux Falls, SD Indianapolis, IN
595 570
Columbus, OH Louisville, KY-IN
551 519
Charlotte-Gastonia-Concord, NC-SC Austin-Round Rock, TX
517 516
New Haven, CT Nashville-Davidson-Murfreesboro, TN
506 505
Des Moines, IA Richmond, VA
501 490
Dover, DE Fargo, ND-MN
456 432
Wichita, KS Ogden-Clearfield, UT
427 423
Little Rock-North Little Rock, AR Jacksonville, FL
404 393
Birmingham-Hoover, AL Colorado Springs, CO
392 372
New Orleans-Metairie-Kenner, LA Memphis, TN-MS-AR
367 348
Buffalo-Niagara Falls, NY Raleigh-Cary, NC
344 336
Allentown-Bethlehem-Easton, PA-NJ Tulsa, OK
334 323
Reno-Sparks, NV Provo-Orem, UT
310 309
Rochester, NY Grand Rapids-Wyoming, MI
307 304
Fresno, CA Tucson, AZ
303 302
Columbia, SC Madison, WI
291 284
Albany-Schenectady-Troy, NY Dayton, OH
268 268
Oxnard-Thousand Oaks-Ventura, CA Baton Rouge, LA
267 262
Charleston, WV Rochester-Dover, NH-ME
262 262
Greensboro-High Point, NC Bakersfield, CA
251 245
El Paso, TX Davenport-Moline-Rock Island, IA-IL
244 240
Toledo, OH Charleston-North Charleston, SC
235 232
Akron, OH Syracuse, NY
231 223
Jackson, MS Fayetteville-Springdale-Rogers, AR-MO
222 215
Bangor, ME Fort Collins-Loveland, CO
208 206
Norwich-New London, CT-RI Savannah, GA
203 202
Poughkeepsie-Newburgh-Middletown, NY Billings, MT
201 199
Lexington-Fayette, KY Cedar Rapids, IA
198 196
Eugene-Springfield, OR McAllen-Edinburg-Pharr, TX
196 195
Stockton, CA Sarasota-Bradenton-Venice, FL
193 192
Durham, NC Greenville, SC
189 185
Topeka, KS Lafayette, LA
182 181
Monroe, LA Scranton-Wilkes Barre, PA
179 176
Harrisburg-Carlisle, PA Boulder, CO
174 171
Salem, OR Knoxville, TN
170 168
Palm Bay-Melbourne-Titusville, FL Chattanooga, TN-GA
168 167
Greeley, CO Augusta-Richmond County, GA-SC
162 161
Springfield, MO Modesto, CA
161 158
Waterbury, CT Lancaster, PA
157 156
Spokane, WA Waterloo-Cedar Falls, IA
156 156
Springfield, MA-CT Youngstown-Warren-Boardman, OH
155 153
Lakeland-Winter Haven, FL Cape Coral-Fort Myers, FL
149 146
Shreveport-Bossier City, LA Worcester, MA-CT
146 144
Reading, PA Bend, OR
142 140
Deltona-Daytona Beach-Ormond Beach, FL Fort Wayne, IN
140 136
Green Bay, WI Vallejo-Fairfield, CA
136 133
Corpus Christi, TX Santa Barbara-Santa Maria-Goleta, CA
132 132
Iowa City, IA Pueblo, CO
131 130
Santa Rosa-Petaluma, CA Kalamazoo-Portage, MI
129 127
Winston-Salem, NC Duluth, MN-WI
127 126
Appleton,WI Beaumont-Port Author, TX
125 123
Champaign-Urbana, IL Visalia-Porterville, CA
122 121
Lansing-East Lansing, MI Racine, WI
119 119
Canton-Massillon, OH Coeur d'Alene, ID
118 117
Huntsville, AL York-Hanover, PA
117 117
Asheville, NC Victoria, TX
116 116
La Crosse, WI Rockford, IL
114 114
Danbury, CT Peoria, IL
112 112
Yakima, WA Atlantic City, NJ
112 111
Eau Claire, WI Mobile, AL
110 110
Port St. Lucie-Fort Pierce, FL Las Cruses, NM
109 107
Pensacola-Ferry Pass-Brent, FL Merced, CA
107 106
Fort Smith, AR-OK Bloomington, IN
105 104
Salinas, CA Montgomery, AL
104 103
Flint, MI Myrtle Beach-Conway-North Myrtle Beach, SC
102 102
Killeen-Temple-Fort Hood, TX El Centro, CA
101 99
Evansville, IN-KY Janesville, WI
99 99
Olympia, WA Spartanburg, SC
99 99
Lawrence, KS Lawton, OK
98 97
Decatur, Al Wausau, WI
96 96
Trenton-Ewing, NJ Harrisonburg, VA
91 90
Muskegon-Norton Shores, MI Laredo, TX
90 89
Amarillo, TX Bremerton-Silverdale, WA
88 87
Erie, PA Kankakee-Bradley, IL
87 87
Kingston, NY Hagerstown-Martinsburg, MD-WV
87 86
Ann Arbor, MI Oshkosh-Neenah, WI
85 85
Altoona, PA Huntington-Ashland, WV-KY-OH
82 82
Medford, OR Naples-Marco Island, FL
82 82
St. Cloud, MN Decatur, IL
82 81
Lake Charles, LA South Bend-Mishawaka, IN-MI
81 81
Fort Walton Beach-Crestview-Destin, FL Utica-Rome, NY
80 80
Brownsville-Harlingen, TX Vero Beach, FL
79 79
Waco, TX Holland-Grand Haven, MI
79 78
Tuscaloosa, AL Fayetteville, NC
78 77
Michigan City-La Porte, IN San Luis Obispo-Paso Robles, CA
77 77
Ocala, FL Springfield, IL
76 76
Barnstable Town, MA Saginaw-Saginaw Township North, MI
75 74
Salisbury, MD Binghamton, NY
74 73
Lynchburg, VA Bellingham, WA
73 70
Gainesville, FL Jackson, MI
70 70
Albany, GA Kingsport-Bristol, TN-VA
68 67
Leominster-Fitchburg-Gardner, MA Roanoke, VA
66 66
Santa-Cruz-Watsonville, CA Athens-Clark County, GA
66 65
Gulfport-Biloxi, MS Longview, TX
65 65
Macon, GA Anderson, SC
65 64
Farmington, NM Florence, AL
64 63
Jacksonville, NC Johnstown, PA
63 63
Lubbock, TX Monroe, MI
63 63
Anderson, IN Anniston-Oxford, AL
62 61
Napa, CA Chico, CA
61 60
Columbus, GA-AL Joplin, MO
59 59
Panama City-Lynn Haven, FL Hickory-Morgantown-Lenoir, NC
59 57
Madera, CA Prescott, AZ
57 54
Vineland-Millville-Bridgeton, NJ Johnson City, TN
54 52
Santa Fe, NM Midland, TX
52 51
Niles-Benton Harbor, MI Punta Gorda, FL
51 48
Columbia, MO Tallahassee, FL
47 43
Valdosta, GA Warner Robins, GA
42 42
Bloomington-Normal IL Springfield, OH
40 34
Ocean City, NJ Bowling Green, KY
30 29
Appleton-Oshkosh-Neenah, WI Grand Rapids-Muskegon-Holland, MI
0 0
Greenville-Spartanburg-Anderson, SC Hinesville-Fort Stewart, GA
0 0
Jamestown, NY Kalamazoo-Battle Creek, MI
0 0
Portsmouth-Rochester, NH-ME
0
#Boston-Cambridge-Quincy, MA-NH
Which metropolitan area has the highest proportion of interviewees of Hispanic ethnicity? Hint: Use tapply() with mean, as in the previous subproblem. Calling sort() on the output of tapply() could also be helpful here.
sort(tapply(CPS$Hispanic,CPS$MetroArea,mean),TRUE)
Laredo, TX McAllen-Edinburg-Pharr, TX
0.966292135 0.948717949
Brownsville-Harlingen, TX El Paso, TX
0.797468354 0.790983607
El Centro, CA San Antonio, TX
0.686868687 0.644151565
Madera, CA Corpus Christi, TX
0.614035088 0.606060606
Merced, CA Salinas, CA
0.566037736 0.557692308
Las Cruses, NM Tucson, AZ
0.542056075 0.506622517
Riverside-San Bernardino, CA Bakersfield, CA
0.502325581 0.489795918
Miami-Fort Lauderdale-Miami Beach, FL Victoria, TX
0.467824968 0.465517241
Santa Fe, NM Los Angeles-Long Beach-Santa Ana, CA
0.461538462 0.460263286
Albuquerque, NM Cape Coral-Fort Myers, FL
0.441707718 0.438356164
Visalia-Porterville, CA Fresno, CA
0.438016529 0.409240924
Vineland-Millville-Bridgeton, NJ Santa Barbara-Santa Maria-Goleta, CA
0.407407407 0.401515152
Killeen-Temple-Fort Hood, TX Oxnard-Thousand Oaks-Ventura, CA
0.386138614 0.359550562
Houston-Baytown-Sugar Land, TX Yakima, WA
0.359005458 0.357142857
Midland, TX Modesto, CA
0.352941176 0.341772152
Danbury, CT Waco, TX
0.339285714 0.329113924
Stockton, CA San Jose-Sunnyvale-Santa Clara, CA
0.321243523 0.316417910
Austin-Round Rock, TX Pueblo, CO
0.310077519 0.307692308
Longview, TX Lubbock, TX
0.292307692 0.285714286
Dallas-Fort Worth-Arlington, TX Poughkeepsie-Newburgh-Middletown, NY
0.283950617 0.273631841
San Diego-Carlsbad-San Marcos, CA Sacramento-Arden-Arcade-Roseville, CA
0.269018743 0.263868066
Amarillo, TX Phoenix-Mesa-Scottsdale, AZ
0.261363636 0.254376931
Las Vegas-Paradise, NV Waterbury, CT
0.251732102 0.248407643
San Luis Obispo-Paso Robles, CA Farmington, NM
0.246753247 0.234375000
Santa Rosa-Petaluma, CA Denver-Aurora, CO
0.232558140 0.232047872
Napa, CA New York-Northern New Jersey-Long Island, NY-NJ-PA
0.229508197 0.228508042
Beaumont-Port Author, TX Springfield, MA-CT
0.227642276 0.219354839
Orlando, FL Salem, OR
0.213114754 0.211764706
Reading, PA Vallejo-Fairfield, CA
0.211267606 0.210526316
Columbus, GA-AL San Francisco-Oakland-Fremont, CA
0.203389831 0.199855700
Reno-Sparks, NV Naples-Marco Island, FL
0.196774194 0.182926829
Chicago-Naperville-Joliet, IN-IN-WI Greeley, CO
0.167388167 0.160493827
Tampa-St. Petersburg-Clearwater, FL Ocala, FL
0.159144893 0.157894737
Fayetteville, NC Salt Lake City, UT
0.155844156 0.154910097
Santa-Cruz-Watsonville, CA Fayetteville-Springdale-Rogers, AR-MO
0.151515152 0.148837209
Boulder, CO Ogden-Clearfield, UT
0.146198830 0.144208038
Grand Rapids-Wyoming, MI Scranton-Wilkes Barre, PA
0.138157895 0.136363636
Lakeland-Winter Haven, FL Wichita, KS
0.134228188 0.133489461
Trenton-Ewing, NJ Prescott, AZ
0.131868132 0.129629630
Jacksonville, NC Green Bay, WI
0.126984127 0.125000000
Lawton, OK Athens-Clark County, GA
0.123711340 0.123076923
Kansas City, MO-KS Washington-Arlington-Alexandria, DC-VA-MD-WV
0.121621622 0.121378980
Fort Collins-Loveland, CO Olympia, WA
0.121359223 0.121212121
Colorado Springs, CO Raleigh-Cary, NC
0.120967742 0.119047619
Charlotte-Gastonia-Concord, NC-SC Chico, CA
0.117988395 0.116666667
Kankakee-Bradley, IL Tulsa, OK
0.114942529 0.114551084
Providence-Fall River-Warwick, MA-RI Fort Walton Beach-Crestview-Destin, FL
0.114273205 0.112500000
Bridgeport-Stamford-Norwalk, CT New Orleans-Metairie-Kenner, LA
0.112328767 0.111716621
Durham, NC Waterloo-Cedar Falls, IA
0.111111111 0.108974359
Oklahoma City, OK Hartford-West Hartford-East Hartford, CT
0.107615894 0.105084746
Norwich-New London, CT-RI Lancaster, PA
0.103448276 0.102564103
Tuscaloosa, AL Port St. Lucie-Fort Pierce, FL
0.102564103 0.100917431
Deltona-Daytona Beach-Ormond Beach, FL Portland-Vancouver-Beaverton, OR-WA
0.100000000 0.094582185
Topeka, KS Augusta-Richmond County, GA-SC
0.093406593 0.093167702
Boise City-Nampa, ID Davenport-Moline-Rock Island, IA-IL
0.093167702 0.091666667
Jacksonville, FL Leominster-Fitchburg-Gardner, MA
0.091603053 0.090909091
Atlantic City, NJ Seattle-Tacoma-Bellevue, WA
0.090090090 0.088446215
Hickory-Morgantown-Lenoir, NC Allentown-Bethlehem-Easton, PA-NJ
0.087719298 0.086826347
Fort Smith, AR-OK Atlanta-Sandy Springs-Marietta, GA
0.085714286 0.085695876
Milwaukee-Waukesha-West Allis, WI Medford, OR
0.085434174 0.085365854
Lansing-East Lansing, MI Worcester, MA-CT
0.084033613 0.083333333
Baltimore-Towson, MD Shreveport-Bossier City, LA
0.082265678 0.082191781
Syracuse, NY Columbia, SC
0.080717489 0.079037801
Philadelphia-Camden-Wilmington, PA-NJ-DE Chattanooga, TN-GA
0.078458844 0.077844311
Eugene-Springfield, OR Canton-Massillon, OH
0.076530612 0.076271186
Vero Beach, FL Greensboro-High Point, NC
0.075949367 0.075697211
Utica-Rome, NY Des Moines, IA
0.075000000 0.073852295
New Haven, CT Indianapolis, IN
0.073122530 0.071929825
Omaha-Council Bluffs, NE-IA Tallahassee, FL
0.070010449 0.069767442
Boston-Cambridge-Quincy, MA-NH Nashville-Davidson-Murfreesboro, TN
0.069537909 0.069306931
Kingston, NY Panama City-Lynn Haven, FL
0.068965517 0.067796610
Ocean City, NJ Provo-Orem, UT
0.066666667 0.064724919
Anderson, IN Monroe, MI
0.064516129 0.063492063
Peoria, IL Lafayette, LA
0.062500000 0.060773481
Asheville, NC Cleveland-Elyria-Mentor, OH
0.060344828 0.060205580
Honolulu, HI Myrtle Beach-Conway-North Myrtle Beach, SC
0.059644670 0.058823529
Racine, WI Rochester, NY
0.058823529 0.058631922
Bremerton-Silverdale, WA Dover, DE
0.057471264 0.057017544
Winston-Salem, NC Birmingham-Hoover, AL
0.055118110 0.053571429
Palm Bay-Melbourne-Titusville, FL Decatur, Al
0.053571429 0.052083333
Minneapolis-St Paul-Bloomington, MN-WI Virginia Beach-Norfolk-Newport News, VA-NC
0.052008239 0.050251256
South Bend-Mishawaka, IN-MI Anniston-Oxford, AL
0.049382716 0.049180328
Valdosta, GA Sarasota-Bradenton-Venice, FL
0.047619048 0.046875000
Albany, GA Rockford, IL
0.044117647 0.043859649
Columbus, OH Springfield, MO
0.043557169 0.043478261
Gainesville, FL Richmond, VA
0.042857143 0.042857143
York-Hanover, PA Columbia, MO
0.042735043 0.042553191
Sioux Falls, SD Punta Gorda, FL
0.042016807 0.041666667
Binghamton, NY Albany-Schenectady-Troy, NY
0.041095890 0.041044776
Lawrence, KS Lexington-Fayette, KY
0.040816327 0.040404040
Cincinnati-Middletown, OH-KY-IN Flint, MI
0.040333797 0.039215686
Michigan City-La Porte, IN Louisville, KY-IN
0.038961039 0.038535645
Johnson City, TN Baton Rouge, LA
0.038461538 0.038167939
Greenville, SC Detroit-Warren-Livonia, MI
0.037837838 0.037666174
Little Rock-North Little Rock, AR Fort Wayne, IN
0.037128713 0.036764706
Toledo, OH Champaign-Urbana, IL
0.034042553 0.032786885
Youngstown-Warren-Boardman, OH Kalamazoo-Portage, MI
0.032679739 0.031496063
Iowa City, IA Rochester-Dover, NH-ME
0.030534351 0.030534351
St. Louis, MO-IL Janesville, WI
0.030334728 0.030303030
Roanoke, VA Billings, MT
0.030303030 0.030150754
Springfield, OH Memphis, TN-MS-AR
0.029411765 0.028735632
Pensacola-Ferry Pass-Brent, FL Lynchburg, VA
0.028037383 0.027397260
Saginaw-Saginaw Township North, MI Coeur d'Alene, ID
0.027027027 0.025641026
Spokane, WA Fargo, ND-MN
0.025641026 0.025462963
Lake Charles, LA Madison, WI
0.024691358 0.024647887
Erie, PA Harrisburg-Carlisle, PA
0.022988506 0.022988506
Muskegon-Norton Shores, MI Bend, OR
0.022222222 0.021428571
Evansville, IN-KY Spartanburg, SC
0.020202020 0.020202020
Niles-Benton Harbor, MI La Crosse, WI
0.019607843 0.017543860
Buffalo-Niagara Falls, NY Charleston-North Charleston, SC
0.017441860 0.017241379
Joplin, MO Pittsburgh, PA
0.016949153 0.016393443
Duluth, MN-WI Gulfport-Biloxi, MS
0.015873016 0.015384615
Cedar Rapids, IA Kingsport-Bristol, TN-VA
0.015306122 0.014925373
Bangor, ME Bellingham, WA
0.014423077 0.014285714
Springfield, IL Akron, OH
0.013157895 0.012987013
Holland-Grand Haven, MI Altoona, PA
0.012820513 0.012195122
St. Cloud, MN Oshkosh-Neenah, WI
0.012195122 0.011764706
Portland-South Portland, ME Wausau, WI
0.011412268 0.010416667
Montgomery, AL Burlington-South Burlington, VT
0.009708738 0.009132420
Jackson, MS Appleton,WI
0.009009009 0.008000000
Charleston, WV Knoxville, TN
0.007633588 0.005952381
Monroe, LA Dayton, OH
0.005586592 0.003731343
Anderson, SC Ann Arbor, MI
0.000000000 0.000000000
Barnstable Town, MA Bloomington, IN
0.000000000 0.000000000
Bloomington-Normal IL Bowling Green, KY
0.000000000 0.000000000
Decatur, IL Eau Claire, WI
0.000000000 0.000000000
Florence, AL Hagerstown-Martinsburg, MD-WV
0.000000000 0.000000000
Harrisonburg, VA Huntington-Ashland, WV-KY-OH
0.000000000 0.000000000
Huntsville, AL Jackson, MI
0.000000000 0.000000000
Johnstown, PA Macon, GA
0.000000000 0.000000000
Mobile, AL Salisbury, MD
0.000000000 0.000000000
Savannah, GA Warner Robins, GA
0.000000000 0.000000000
#Laredo, TX
Remembering that CPS$Race == “Asian” returns a TRUE/FALSE vector of whether an interviewee is Asian, determine the number of metropolitan areas in the United States from which at least 20% of interviewees are Asian.
head(sort(tapply(CPS$Race == "Asian",CPS$MetroArea, mean),TRUE))
Honolulu, HI San Francisco-Oakland-Fremont, CA San Jose-Sunnyvale-Santa Clara, CA Vallejo-Fairfield, CA
0.5019036 0.2467532 0.2417910 0.2030075
Fresno, CA Warner Robins, GA
0.1848185 0.1666667
#4
Normally, we would look at the sorted proportion of interviewees from each metropolitan area who have not received a high school diploma with the command:
sort(tapply(CPS$Education == "No high school diploma", CPS$MetroArea, mean))
However, none of the interviewees aged 14 and younger have an education value reported, so the mean value is reported as NA for each metropolitan area. To get mean (and related functions, like sum) to ignore missing values, you can pass the parameter na.rm=TRUE. Passing na.rm=TRUE to the tapply function, determine which metropolitan area has the smallest proportion of interviewees who have received no high school diploma.
sort(tapply(CPS$Education == "No high school diploma", CPS$MetroArea, mean,na.rm=TRUE),FALSE)
Iowa City, IA Bowling Green, KY
0.02912621 0.03703704
Kalamazoo-Portage, MI Champaign-Urbana, IL
0.05050505 0.05154639
Bremerton-Silverdale, WA Lawrence, KS
0.05405405 0.05952381
Bloomington-Normal IL Jacksonville, NC
0.06060606 0.06122449
Eau Claire, WI Palm Bay-Melbourne-Titusville, FL
0.06250000 0.06666667
Salisbury, MD Gainesville, FL
0.06779661 0.06896552
Fort Collins-Loveland, CO Altoona, PA
0.06936416 0.07142857
Madison, WI Tallahassee, FL
0.07423581 0.07500000
Fargo, ND-MN Albany-Schenectady-Troy, NY
0.07902736 0.07929515
Ocean City, NJ Lakeland-Winter Haven, FL
0.08000000 0.08130081
Billings, MT Coeur d'Alene, ID
0.08280255 0.08333333
Burlington-South Burlington, VT Akron, OH
0.08394161 0.08421053
Ann Arbor, MI Asheville, NC
0.08695652 0.08695652
Pensacola-Ferry Pass-Brent, FL Oshkosh-Neenah, WI
0.08695652 0.08823529
Rochester-Dover, NH-ME Knoxville, TN
0.08928571 0.08965517
Pittsburgh, PA Barnstable Town, MA
0.09060403 0.09090909
Bridgeport-Stamford-Norwalk, CT Johnstown, PA
0.09563758 0.09615385
Austin-Round Rock, TX La Crosse, WI
0.09629630 0.09677419
Boulder, CO Charleston-North Charleston, SC
0.09701493 0.09890110
Fort Wayne, IN Roanoke, VA
0.09900990 0.10169492
Prescott, AZ Santa Rosa-Petaluma, CA
0.10204082 0.10280374
Evansville, IN-KY Spokane, WA
0.10389610 0.10434783
Poughkeepsie-Newburgh-Middletown, NY Tampa-St. Petersburg-Clearwater, FL
0.10559006 0.10579710
Grand Rapids-Wyoming, MI Portland-South Portland, ME
0.10612245 0.10638298
Honolulu, HI Michigan City-La Porte, IN
0.10739300 0.10769231
Eugene-Springfield, OR Boston-Cambridge-Quincy, MA-NH
0.11038961 0.11080485
Bend, OR Vero Beach, FL
0.11111111 0.11428571
Sarasota-Bradenton-Venice, FL Fort Walton Beach-Crestview-Destin, FL
0.11464968 0.11475410
Flint, MI Cedar Rapids, IA
0.11538462 0.11564626
Minneapolis-St Paul-Bloomington, MN-WI Portland-Vancouver-Beaverton, OR-WA
0.11638204 0.11657143
Washington-Arlington-Alexandria, DC-VA-MD-WV Mobile, AL
0.11683748 0.11702128
Scranton-Wilkes Barre, PA Topeka, KS
0.11724138 0.11724138
Colorado Springs, CO Olympia, WA
0.11764706 0.11764706
Reno-Sparks, NV Appleton,WI
0.11764706 0.11827957
Santa Fe, NM Virginia Beach-Norfolk-Newport News, VA-NC
0.11904762 0.11909651
Allentown-Bethlehem-Easton, PA-NJ Rochester, NY
0.11929825 0.12132353
Seattle-Tacoma-Bellevue, WA Kansas City, MO-KS
0.12168793 0.12172775
Napa, CA Duluth, MN-WI
0.12244898 0.12264151
New Haven, CT Canton-Massillon, OH
0.12354312 0.12371134
Fayetteville, NC San Luis Obispo-Paso Robles, CA
0.12500000 0.12500000
Worcester, MA-CT Philadelphia-Camden-Wilmington, PA-NJ-DE
0.12605042 0.12717253
Davenport-Moline-Rock Island, IA-IL Waterloo-Cedar Falls, IA
0.12727273 0.12800000
Pueblo, CO Baton Rouge, LA
0.12844037 0.12871287
Racine, WI Des Moines, IA
0.12903226 0.12944162
Detroit-Warren-Livonia, MI Omaha-Council Bluffs, NE-IA
0.12964642 0.12972973
Richmond, VA Savannah, GA
0.12990196 0.13013699
Danbury, CT Bloomington, IN
0.13043478 0.13095238
Valdosta, GA Wausau, WI
0.13157895 0.13157895
Deltona-Daytona Beach-Ormond Beach, FL Tulsa, OK
0.13178295 0.13178295
Harrisburg-Carlisle, PA Las Vegas-Paradise, NV
0.13286713 0.13307985
Myrtle Beach-Conway-North Myrtle Beach, SC Provo-Orem, UT
0.13333333 0.13366337
Anderson, IN Chico, CA
0.13461538 0.13461538
St. Louis, MO-IL Niles-Benton Harbor, MI
0.13461538 0.13513514
Ogden-Clearfield, UT Baltimore-Towson, MD
0.13571429 0.13583333
Buffalo-Niagara Falls, NY Milwaukee-Waukesha-West Allis, WI
0.13684211 0.13693694
Chicago-Naperville-Joliet, IN-IN-WI Louisville, KY-IN
0.13737734 0.13785047
Lynchburg, VA Peoria, IL
0.13793103 0.13829787
Sioux Falls, SD Ocala, FL
0.13832200 0.13888889
Leominster-Fitchburg-Gardner, MA Oklahoma City, OK
0.14035088 0.14137214
San Diego-Carlsbad-San Marcos, CA Jacksonville, FL
0.14188267 0.14244186
Atlantic City, NJ Holland-Grand Haven, MI
0.14285714 0.14285714
Medford, OR Naples-Marco Island, FL
0.14285714 0.14285714
Punta Gorda, FL Victoria, TX
0.14285714 0.14285714
Winston-Salem, NC Salt Lake City, UT
0.14285714 0.14338235
Atlanta-Sandy Springs-Marietta, GA Decatur, IL
0.14421553 0.14516129
Springfield, IL Monroe, MI
0.14516129 0.14545455
Denver-Aurora, CO Hartford-West Hartford-East Hartford, CT
0.14574558 0.14574899
Greeley, CO San Francisco-Oakland-Fremont, CA
0.14615385 0.14651368
Boise City-Nampa, ID Greenville, SC
0.14653465 0.14666667
Birmingham-Hoover, AL Saginaw-Saginaw Township North, MI
0.14678899 0.14754098
Santa-Cruz-Watsonville, CA Trenton-Ewing, NJ
0.14814815 0.14814815
Lexington-Fayette, KY San Jose-Sunnyvale-Santa Clara, CA
0.14838710 0.14922481
Bellingham, WA Norwich-New London, CT-RI
0.15000000 0.15060241
Lubbock, TX Huntington-Ashland, WV-KY-OH
0.15094340 0.15151515
St. Cloud, MN Jackson, MS
0.15151515 0.15168539
Dayton, OH Chattanooga, TN-GA
0.15207373 0.15217391
Syracuse, NY New York-Northern New Jersey-Long Island, NY-NJ-PA
0.15428571 0.15573586
Columbia, SC Columbus, OH
0.15600000 0.15617716
Memphis, TN-MS-AR Orlando, FL
0.15714286 0.16108787
Warner Robins, GA Cleveland-Elyria-Mentor, OH
0.16216216 0.16250000
Columbia, MO Durham, NC
0.16279070 0.16326531
Miami-Fort Lauderdale-Miami Beach, FL Indianapolis, IN
0.16356589 0.16371681
Albuquerque, NM Cape Coral-Fort Myers, FL
0.16424116 0.16528926
Amarillo, TX Anniston-Oxford, AL
0.16666667 0.16666667
Athens-Clark County, GA Binghamton, NY
0.16666667 0.16666667
Phoenix-Mesa-Scottsdale, AZ Green Bay, WI
0.16687737 0.16831683
Bangor, ME Providence-Fall River-Warwick, MA-RI
0.16860465 0.16915688
Muskegon-Norton Shores, MI Tuscaloosa, AL
0.16923077 0.16949153
Rockford, IL Las Cruses, NM
0.17021277 0.17283951
Gulfport-Biloxi, MS Huntsville, AL
0.17307692 0.17391304
Utica-Rome, NY Fort Smith, AR-OK
0.17391304 0.17441860
Charlotte-Gastonia-Concord, NC-SC El Centro, CA
0.17444717 0.17567568
Erie, PA Jackson, MI
0.17567568 0.17741935
Cincinnati-Middletown, OH-KY-IN Springfield, MA-CT
0.17773788 0.17829457
Reading, PA Vallejo-Fairfield, CA
0.17857143 0.17924528
Salem, OR Nashville-Davidson-Murfreesboro, TN
0.17985612 0.18112245
Johnson City, TN Wichita, KS
0.18181818 0.18181818
York-Hanover, PA Janesville, WI
0.18181818 0.18292683
Lansing-East Lansing, MI Greensboro-High Point, NC
0.18348624 0.18357488
Decatur, Al Albany, GA
0.18421053 0.18604651
Augusta-Richmond County, GA-SC Charleston, WV
0.18796992 0.18834081
Shreveport-Bossier City, LA Raleigh-Cary, NC
0.18918919 0.18959108
Toledo, OH Spartanburg, SC
0.18965517 0.18987342
Dallas-Fort Worth-Arlington, TX Sacramento-Arden-Arcade-Roseville, CA
0.19077135 0.19136961
Santa Barbara-Santa Maria-Goleta, CA Monroe, LA
0.19191919 0.19205298
Dover, DE South Bend-Mishawaka, IN-MI
0.19220056 0.19354839
Fayetteville-Springdale-Rogers, AR-MO Columbus, GA-AL
0.19393939 0.19607843
Kingston, NY Port St. Lucie-Fort Pierce, FL
0.19696970 0.19767442
Waterbury, CT Little Rock-North Little Rock, AR
0.19852941 0.19939577
Springfield, MO Modesto, CA
0.20000000 0.20325203
Houston-Baytown-Sugar Land, TX Oxnard-Thousand Oaks-Ventura, CA
0.20439739 0.20657277
Anderson, SC Midland, TX
0.20689655 0.21052632
New Orleans-Metairie-Kenner, LA Fresno, CA
0.21088435 0.21120690
Lake Charles, LA Visalia-Porterville, CA
0.21739130 0.21782178
San Antonio, TX Hagerstown-Martinsburg, MD-WV
0.22004357 0.22222222
Yakima, WA Hickory-Morgantown-Lenoir, NC
0.22222222 0.22448980
Los Angeles-Long Beach-Santa Ana, CA Panama City-Lynn Haven, FL
0.22882883 0.22916667
Harrisonburg, VA Kankakee-Bradley, IL
0.23287671 0.23437500
Beaumont-Port Author, TX Youngstown-Warren-Boardman, OH
0.23469388 0.23622047
Riverside-San Bernardino, CA Farmington, NM
0.23780488 0.23913043
Killeen-Temple-Fort Hood, TX Waco, TX
0.24050633 0.24074074
Montgomery, AL Tucson, AZ
0.24137931 0.24603175
Lafayette, LA Joplin, MO
0.24822695 0.25000000
Stockton, CA Brownsville-Harlingen, TX
0.25333333 0.25396825
Lancaster, PA Bakersfield, CA
0.26771654 0.27218935
Vineland-Millville-Bridgeton, NJ Lawton, OK
0.27500000 0.28000000
Merced, CA Corpus Christi, TX
0.28358209 0.29702970
El Paso, TX Springfield, OH
0.30219780 0.31034483
Florence, AL Madera, CA
0.32075472 0.33333333
Salinas, CA Laredo, TX
0.34090909 0.34426230
Kingsport-Bristol, TN-VA Longview, TX
0.36363636 0.38297872
McAllen-Edinburg-Pharr, TX Macon, GA
0.38297872 0.40816327
#Iowa City, IA
Just as we did with the metropolitan area information, merge in the country of birth information from the CountryMap data frame, replacing the CPS data frame with the result. If you accidentally overwrite CPS with the wrong values, remember that you can restore it by re-loading the data frame from CPSData.csv and then merging in the metropolitan area information using the command provided in the previous subproblem.
What is the name of the variable added to the CPS data frame by this merge operation?
names(CountryMap)
[1] "Code" "Country"
CPS = merge(CPS, CountryMap, by.x="CountryOfBirthCode", by.y="Code", all.x=TRUE)
str(CPS)
'data.frame': 131302 obs. of 16 variables:
$ CountryOfBirthCode: int 57 57 57 57 57 57 57 57 57 57 ...
$ MetroAreaCode : int 10420 71650 10420 10420 10420 10420 10420 10420 10420 10420 ...
$ PeopleInHousehold : int 2 4 5 2 2 3 1 3 4 4 ...
$ Region : Factor w/ 4 levels "Midwest","Northeast",..: 1 2 1 1 1 1 1 1 1 1 ...
$ State : Factor w/ 51 levels "Alabama","Alaska",..: 36 30 36 36 36 36 36 36 36 36 ...
$ Age : int 73 5 10 30 30 0 34 32 6 9 ...
$ Married : Factor w/ 5 levels "Divorced","Married",..: 2 NA NA 2 2 NA 1 2 NA NA ...
$ Sex : Factor w/ 2 levels "Female","Male": 1 1 1 1 1 2 2 2 1 2 ...
$ Education : Factor w/ 8 levels "Associate degree",..: 8 NA NA 1 2 NA 4 4 NA NA ...
$ Race : Factor w/ 6 levels "American Indian",..: 6 6 6 6 6 6 6 6 6 6 ...
$ Hispanic : int 0 0 0 0 0 0 0 0 1 0 ...
$ Citizenship : Factor w/ 3 levels "Citizen, Native",..: 1 1 1 1 1 1 1 1 1 1 ...
$ EmploymentStatus : Factor w/ 5 levels "Disabled","Employed",..: 4 NA NA 2 2 NA 2 2 NA NA ...
$ Industry : Factor w/ 14 levels "Agriculture, forestry, fishing, and hunting",..: NA NA NA 13 9 NA 3 13 NA NA ...
$ MetroArea : Factor w/ 271 levels "Akron, OH","Albany, GA",..: 1 34 1 1 1 1 1 1 1 1 ...
$ Country : Factor w/ 149 levels "Afghanistan",..: 140 140 140 140 140 140 140 140 140 140 ...
#Country
How many interviewees have a missing value for the new country of birth variable?
sum(is.na(CPS$Country))
[1] 176
Among all interviewees born outside of North America, which country was the most common place of birth?
sort(table(CPS$Country),TRUE)
United States Mexico Philippines India
115063 3921 839 770
China Puerto Rico El Salvador Vietnam
581 518 477 458
Germany Cuba Canada Korea
438 426 410 334
Dominican Republic Guatemala Jamaica Columbia
330 309 217 206
Honduras Japan England Russia
189 187 179 173
Haiti Poland Brazil Italy
167 162 159 149
Iran Ecuador Peru Africa, not specified
144 136 136 129
Thailand United Kingdom Guyana Pakistan
128 111 109 109
Ukraine Taiwan Laos Iraq
104 102 98 97
Nigeria Elsewhere Ethiopia Ghana
85 81 80 76
Nicaragua France South Korea Somalia
76 73 73 72
Egypt Argentina Hong Kong Portugal
65 64 64 64
Bosnia & Herzegovina Venezuela Trinidad and Tobago Israel
61 61 60 57
Greece Kenya Romania Liberia
56 55 55 52
Cambodia South Africa Turkey Lebanon
49 48 48 45
Myanmar (Burma) Nepal Panama Australia
45 44 44 43
Bangladesh Spain Asia, not specified Ireland
42 41 39 39
Chile Jordan Armenia Cameroon
37 36 35 32
Syria Guam Bulgaria Costa Rica
32 31 29 29
Saudi Arabia Netherlands Sweden Afghanistan
29 28 28 26
Indonesia Hungary Belarus Scotland
26 25 24 24
Yugoslavia New Zealand Switzerland Yemen
24 23 23 23
Azores USSR Malaysia Serbia
22 22 20 20
Europe, not specified Uzbekistan West Indies, not specified Albania
19 19 19 18
Norway Austria Morocco Sri Lanka
18 17 17 17
U. S. Virgin Islands Uruguay Cape Verde Eritrea
17 17 15 15
Sierra Leone Uganda Antigua and Barbuda Belgium
15 15 13 13
Bermuda Bolivia Grenada Sudan
13 13 13 13
Croatia Macedonia Moldova Czech Republic
12 12 12 11
Dominica Paraguay Bahamas Finland
11 11 10 10
Kuwait Lithuania Algeria Americas, not specified
10 10 9 9
Belize Fiji St. Vincent and the Grenadines South America, not specified
9 9 9 7
St. Lucia Barbados Denmark Latvia
7 6 6 6
Samoa Senegal Singapore Slovakia
6 6 6 6
Tonga Zimbabwe Georgia Azerbaijan
6 6 5 3
Czechoslovakia St. Kitts--Nevis Northern Ireland Tanzania
3 3 2 2
Cyprus Kosovo Oceania, not specified Other U. S. Island Areas
0 0 0 0
Wales
0
# Philippines
What proportion of the interviewees from the “New York-Northern New Jersey-Long Island, NY-NJ-PA” metropolitan area have a country of birth that is not the United States? For this computation, don’t include people from this metropolitan area who have a missing country of birth.
table(CPS$MetroArea=="New York-Northern New Jersey-Long Island, NY-NJ-PA",CPS$Country!="United States")
FALSE TRUE
FALSE 78757 12744
TRUE 3736 1668
sum(CPS$MetroArea=="New York-Northern New Jersey-Long Island, NY-NJ-PA",na.rm=TRUE)
[1] 5409
#5 have a missing country of origin
1668/(1668+3736)
[1] 0.3086603
Which metropolitan area has the largest number (note – not proportion) of interviewees with a country of birth in India? Hint – remember to include na.rm=TRUE if you are using tapply() to answer this question.
sort(tapply(CPS$Country == "India", CPS$MetroArea, sum, na.rm=TRUE),TRUE)
New York-Northern New Jersey-Long Island, NY-NJ-PA Washington-Arlington-Alexandria, DC-VA-MD-WV
96 50
Philadelphia-Camden-Wilmington, PA-NJ-DE Chicago-Naperville-Joliet, IN-IN-WI
32 31
Detroit-Warren-Livonia, MI Atlanta-Sandy Springs-Marietta, GA
30 27
San Francisco-Oakland-Fremont, CA Hartford-West Hartford-East Hartford, CT
27 26
Minneapolis-St Paul-Bloomington, MN-WI Los Angeles-Long Beach-Santa Ana, CA
23 19
San Jose-Sunnyvale-Santa Clara, CA Dallas-Fort Worth-Arlington, TX
19 18
Baltimore-Towson, MD Fresno, CA
16 16
Pittsburgh, PA Houston-Baytown-Sugar Land, TX
16 15
Providence-Fall River-Warwick, MA-RI Bridgeport-Stamford-Norwalk, CT
14 12
Milwaukee-Waukesha-West Allis, WI Boston-Cambridge-Quincy, MA-NH
12 11
Kansas City, MO-KS Honolulu, HI
11 9
Fayetteville-Springdale-Rogers, AR-MO Sacramento-Arden-Arcade-Roseville, CA
8 8
Tampa-St. Petersburg-Clearwater, FL Austin-Round Rock, TX
7 6
Brownsville-Harlingen, TX Des Moines, IA
6 6
Little Rock-North Little Rock, AR New Haven, CT
6 6
Portland-Vancouver-Beaverton, OR-WA Warner Robins, GA
6 6
Orlando, FL Seattle-Tacoma-Bellevue, WA
5 5
Charlotte-Gastonia-Concord, NC-SC Indianapolis, IN
4 4
Omaha-Council Bluffs, NE-IA Peoria, IL
4 4
Rochester-Dover, NH-ME San Diego-Carlsbad-San Marcos, CA
4 4
Trenton-Ewing, NJ Tulsa, OK
4 4
Albuquerque, NM Iowa City, IA
3 3
Madison, WI Norwich-New London, CT-RI
3 3
Reno-Sparks, NV Visalia-Porterville, CA
3 3
Atlantic City, NJ Bakersfield, CA
2 2
Birmingham-Hoover, AL Burlington-South Burlington, VT
2 2
Charleston-North Charleston, SC Cleveland-Elyria-Mentor, OH
2 2
Deltona-Daytona Beach-Ormond Beach, FL Fort Wayne, IN
2 2
Las Vegas-Paradise, NV Memphis, TN-MS-AR
2 2
Miami-Fort Lauderdale-Miami Beach, FL Nashville-Davidson-Murfreesboro, TN
2 2
Ogden-Clearfield, UT Oklahoma City, OK
2 2
Oxnard-Thousand Oaks-Ventura, CA Phoenix-Mesa-Scottsdale, AZ
2 2
Rochester, NY Salt Lake City, UT
2 2
Springfield, IL Winston-Salem, NC
2 2
Anderson, SC Bloomington-Normal IL
1 1
Boise City-Nampa, ID Cincinnati-Middletown, OH-KY-IN
1 1
Columbia, SC Greenville, SC
1 1
Harrisburg-Carlisle, PA Jacksonville, FL
1 1
Lawrence, KS Naples-Marco Island, FL
1 1
New Orleans-Metairie-Kenner, LA Olympia, WA
1 1
Provo-Orem, UT Syracuse, NY
1 1
Tucson, AZ Akron, OH
1 0
Albany, GA Albany-Schenectady-Troy, NY
0 0
Allentown-Bethlehem-Easton, PA-NJ Altoona, PA
0 0
Amarillo, TX Anderson, IN
0 0
Ann Arbor, MI Anniston-Oxford, AL
0 0
Appleton,WI Asheville, NC
0 0
Athens-Clark County, GA Augusta-Richmond County, GA-SC
0 0
Bangor, ME Barnstable Town, MA
0 0
Baton Rouge, LA Beaumont-Port Author, TX
0 0
Bellingham, WA Bend, OR
0 0
Billings, MT Binghamton, NY
0 0
Bloomington, IN Boulder, CO
0 0
Bowling Green, KY Bremerton-Silverdale, WA
0 0
Buffalo-Niagara Falls, NY Canton-Massillon, OH
0 0
Cape Coral-Fort Myers, FL Cedar Rapids, IA
0 0
Champaign-Urbana, IL Charleston, WV
0 0
Chattanooga, TN-GA Chico, CA
0 0
Coeur d'Alene, ID Colorado Springs, CO
0 0
Columbia, MO Columbus, GA-AL
0 0
Columbus, OH Corpus Christi, TX
0 0
Danbury, CT Davenport-Moline-Rock Island, IA-IL
0 0
Dayton, OH Decatur, Al
0 0
Decatur, IL Denver-Aurora, CO
0 0
Dover, DE Duluth, MN-WI
0 0
Durham, NC Eau Claire, WI
0 0
El Centro, CA El Paso, TX
0 0
Erie, PA Eugene-Springfield, OR
0 0
Evansville, IN-KY Fargo, ND-MN
0 0
Farmington, NM Fayetteville, NC
0 0
Flint, MI Florence, AL
0 0
Fort Collins-Loveland, CO Fort Smith, AR-OK
0 0
Fort Walton Beach-Crestview-Destin, FL Gainesville, FL
0 0
Grand Rapids-Wyoming, MI Greeley, CO
0 0
Green Bay, WI Greensboro-High Point, NC
0 0
Gulfport-Biloxi, MS Hagerstown-Martinsburg, MD-WV
0 0
Harrisonburg, VA Hickory-Morgantown-Lenoir, NC
0 0
Holland-Grand Haven, MI Huntington-Ashland, WV-KY-OH
0 0
Huntsville, AL Jackson, MI
0 0
Jackson, MS Jacksonville, NC
0 0
Janesville, WI Johnson City, TN
0 0
Johnstown, PA Joplin, MO
0 0
Kalamazoo-Portage, MI Kankakee-Bradley, IL
0 0
Killeen-Temple-Fort Hood, TX Kingsport-Bristol, TN-VA
0 0
Kingston, NY Knoxville, TN
0 0
La Crosse, WI Lafayette, LA
0 0
Lake Charles, LA Lakeland-Winter Haven, FL
0 0
Lancaster, PA Lansing-East Lansing, MI
0 0
Laredo, TX Las Cruses, NM
0 0
Lawton, OK Leominster-Fitchburg-Gardner, MA
0 0
Lexington-Fayette, KY Longview, TX
0 0
Louisville, KY-IN Lubbock, TX
0 0
Lynchburg, VA Macon, GA
0 0
Madera, CA McAllen-Edinburg-Pharr, TX
0 0
Medford, OR Merced, CA
0 0
Michigan City-La Porte, IN Midland, TX
0 0
Mobile, AL Modesto, CA
0 0
Monroe, LA Monroe, MI
0 0
Montgomery, AL Muskegon-Norton Shores, MI
0 0
Myrtle Beach-Conway-North Myrtle Beach, SC Napa, CA
0 0
Niles-Benton Harbor, MI Ocala, FL
0 0
Ocean City, NJ Oshkosh-Neenah, WI
0 0
Palm Bay-Melbourne-Titusville, FL Panama City-Lynn Haven, FL
0 0
Pensacola-Ferry Pass-Brent, FL Port St. Lucie-Fort Pierce, FL
0 0
Portland-South Portland, ME Poughkeepsie-Newburgh-Middletown, NY
0 0
Prescott, AZ Pueblo, CO
0 0
Punta Gorda, FL Racine, WI
0 0
Raleigh-Cary, NC Reading, PA
0 0
Richmond, VA Riverside-San Bernardino, CA
0 0
Roanoke, VA Rockford, IL
0 0
Saginaw-Saginaw Township North, MI Salem, OR
0 0
Salinas, CA Salisbury, MD
0 0
San Antonio, TX San Luis Obispo-Paso Robles, CA
0 0
Santa Barbara-Santa Maria-Goleta, CA Santa Fe, NM
0 0
Santa Rosa-Petaluma, CA Santa-Cruz-Watsonville, CA
0 0
Sarasota-Bradenton-Venice, FL Savannah, GA
0 0
Scranton-Wilkes Barre, PA Shreveport-Bossier City, LA
0 0
Sioux Falls, SD South Bend-Mishawaka, IN-MI
0 0
Spartanburg, SC Spokane, WA
0 0
Springfield, MA-CT Springfield, MO
0 0
Springfield, OH St. Cloud, MN
0 0
St. Louis, MO-IL Stockton, CA
0 0
Tallahassee, FL Toledo, OH
0 0
Topeka, KS Tuscaloosa, AL
0 0
Utica-Rome, NY Valdosta, GA
0 0
Vallejo-Fairfield, CA Vero Beach, FL
0 0
Victoria, TX Vineland-Millville-Bridgeton, NJ
0 0
Virginia Beach-Norfolk-Newport News, VA-NC Waco, TX
0 0
Waterbury, CT Waterloo-Cedar Falls, IA
0 0
Wausau, WI Wichita, KS
0 0
Worcester, MA-CT Yakima, WA
0 0
York-Hanover, PA Youngstown-Warren-Boardman, OH
0 0
#New York-Northern New Jersey-Long Island, NY-NJ-PA
In Brazil?
sort(tapply(CPS$Country == "Brazil", CPS$MetroArea, sum, na.rm=TRUE),TRUE)
Boston-Cambridge-Quincy, MA-NH Miami-Fort Lauderdale-Miami Beach, FL
18 16
Los Angeles-Long Beach-Santa Ana, CA Washington-Arlington-Alexandria, DC-VA-MD-WV
9 8
Bridgeport-Stamford-Norwalk, CT New York-Northern New Jersey-Long Island, NY-NJ-PA
7 7
San Francisco-Oakland-Fremont, CA Danbury, CT
6 5
Davenport-Moline-Rock Island, IA-IL Philadelphia-Camden-Wilmington, PA-NJ-DE
4 4
Canton-Massillon, OH Phoenix-Mesa-Scottsdale, AZ
3 3
Providence-Fall River-Warwick, MA-RI Salt Lake City, UT
3 3
Barnstable Town, MA Charlotte-Gastonia-Concord, NC-SC
2 2
Chicago-Naperville-Joliet, IN-IN-WI Columbia, SC
2 2
Dallas-Fort Worth-Arlington, TX Jacksonville, FL
2 2
Orlando, FL Sacramento-Arden-Arcade-Roseville, CA
2 2
Akron, OH Albuquerque, NM
1 1
Atlanta-Sandy Springs-Marietta, GA Bremerton-Silverdale, WA
1 1
Cape Coral-Fort Myers, FL Chico, CA
1 1
Cincinnati-Middletown, OH-KY-IN Denver-Aurora, CO
1 1
Hartford-West Hartford-East Hartford, CT Kansas City, MO-KS
1 1
Leominster-Fitchburg-Gardner, MA Louisville, KY-IN
1 1
Minneapolis-St Paul-Bloomington, MN-WI Monroe, LA
1 1
Montgomery, AL Oxnard-Thousand Oaks-Ventura, CA
1 1
Pensacola-Ferry Pass-Brent, FL Racine, WI
1 1
Rochester, NY Salem, OR
1 1
San Jose-Sunnyvale-Santa Clara, CA Seattle-Tacoma-Bellevue, WA
1 1
Tampa-St. Petersburg-Clearwater, FL Trenton-Ewing, NJ
1 1
Virginia Beach-Norfolk-Newport News, VA-NC Waterbury, CT
1 1
Wichita, KS Albany, GA
1 0
Albany-Schenectady-Troy, NY Allentown-Bethlehem-Easton, PA-NJ
0 0
Altoona, PA Amarillo, TX
0 0
Anderson, IN Anderson, SC
0 0
Ann Arbor, MI Anniston-Oxford, AL
0 0
Appleton,WI Asheville, NC
0 0
Athens-Clark County, GA Atlantic City, NJ
0 0
Augusta-Richmond County, GA-SC Austin-Round Rock, TX
0 0
Bakersfield, CA Baltimore-Towson, MD
0 0
Bangor, ME Baton Rouge, LA
0 0
Beaumont-Port Author, TX Bellingham, WA
0 0
Bend, OR Billings, MT
0 0
Binghamton, NY Birmingham-Hoover, AL
0 0
Bloomington, IN Bloomington-Normal IL
0 0
Boise City-Nampa, ID Boulder, CO
0 0
Bowling Green, KY Brownsville-Harlingen, TX
0 0
Buffalo-Niagara Falls, NY Burlington-South Burlington, VT
0 0
Cedar Rapids, IA Champaign-Urbana, IL
0 0
Charleston, WV Charleston-North Charleston, SC
0 0
Chattanooga, TN-GA Cleveland-Elyria-Mentor, OH
0 0
Coeur d'Alene, ID Colorado Springs, CO
0 0
Columbia, MO Columbus, GA-AL
0 0
Columbus, OH Corpus Christi, TX
0 0
Dayton, OH Decatur, Al
0 0
Decatur, IL Deltona-Daytona Beach-Ormond Beach, FL
0 0
Des Moines, IA Detroit-Warren-Livonia, MI
0 0
Dover, DE Duluth, MN-WI
0 0
Durham, NC Eau Claire, WI
0 0
El Centro, CA El Paso, TX
0 0
Erie, PA Eugene-Springfield, OR
0 0
Evansville, IN-KY Fargo, ND-MN
0 0
Farmington, NM Fayetteville, NC
0 0
Fayetteville-Springdale-Rogers, AR-MO Flint, MI
0 0
Florence, AL Fort Collins-Loveland, CO
0 0
Fort Smith, AR-OK Fort Walton Beach-Crestview-Destin, FL
0 0
Fort Wayne, IN Fresno, CA
0 0
Gainesville, FL Grand Rapids-Wyoming, MI
0 0
Greeley, CO Green Bay, WI
0 0
Greensboro-High Point, NC Greenville, SC
0 0
Gulfport-Biloxi, MS Hagerstown-Martinsburg, MD-WV
0 0
Harrisburg-Carlisle, PA Harrisonburg, VA
0 0
Hickory-Morgantown-Lenoir, NC Holland-Grand Haven, MI
0 0
Honolulu, HI Houston-Baytown-Sugar Land, TX
0 0
Huntington-Ashland, WV-KY-OH Huntsville, AL
0 0
Indianapolis, IN Iowa City, IA
0 0
Jackson, MI Jackson, MS
0 0
Jacksonville, NC Janesville, WI
0 0
Johnson City, TN Johnstown, PA
0 0
Joplin, MO Kalamazoo-Portage, MI
0 0
Kankakee-Bradley, IL Killeen-Temple-Fort Hood, TX
0 0
Kingsport-Bristol, TN-VA Kingston, NY
0 0
Knoxville, TN La Crosse, WI
0 0
Lafayette, LA Lake Charles, LA
0 0
Lakeland-Winter Haven, FL Lancaster, PA
0 0
Lansing-East Lansing, MI Laredo, TX
0 0
Las Cruses, NM Las Vegas-Paradise, NV
0 0
Lawrence, KS Lawton, OK
0 0
Lexington-Fayette, KY Little Rock-North Little Rock, AR
0 0
Longview, TX Lubbock, TX
0 0
Lynchburg, VA Macon, GA
0 0
Madera, CA Madison, WI
0 0
McAllen-Edinburg-Pharr, TX Medford, OR
0 0
Memphis, TN-MS-AR Merced, CA
0 0
Michigan City-La Porte, IN Midland, TX
0 0
Milwaukee-Waukesha-West Allis, WI Mobile, AL
0 0
Modesto, CA Monroe, MI
0 0
Muskegon-Norton Shores, MI Myrtle Beach-Conway-North Myrtle Beach, SC
0 0
Napa, CA Naples-Marco Island, FL
0 0
Nashville-Davidson-Murfreesboro, TN New Haven, CT
0 0
New Orleans-Metairie-Kenner, LA Niles-Benton Harbor, MI
0 0
Norwich-New London, CT-RI Ocala, FL
0 0
Ocean City, NJ Ogden-Clearfield, UT
0 0
Oklahoma City, OK Olympia, WA
0 0
Omaha-Council Bluffs, NE-IA Oshkosh-Neenah, WI
0 0
Palm Bay-Melbourne-Titusville, FL Panama City-Lynn Haven, FL
0 0
Peoria, IL Pittsburgh, PA
0 0
Port St. Lucie-Fort Pierce, FL Portland-South Portland, ME
0 0
Portland-Vancouver-Beaverton, OR-WA Poughkeepsie-Newburgh-Middletown, NY
0 0
Prescott, AZ Provo-Orem, UT
0 0
Pueblo, CO Punta Gorda, FL
0 0
Raleigh-Cary, NC Reading, PA
0 0
Reno-Sparks, NV Richmond, VA
0 0
Riverside-San Bernardino, CA Roanoke, VA
0 0
Rochester-Dover, NH-ME Rockford, IL
0 0
Saginaw-Saginaw Township North, MI Salinas, CA
0 0
Salisbury, MD San Antonio, TX
0 0
San Diego-Carlsbad-San Marcos, CA San Luis Obispo-Paso Robles, CA
0 0
Santa Barbara-Santa Maria-Goleta, CA Santa Fe, NM
0 0
Santa Rosa-Petaluma, CA Santa-Cruz-Watsonville, CA
0 0
Sarasota-Bradenton-Venice, FL Savannah, GA
0 0
Scranton-Wilkes Barre, PA Shreveport-Bossier City, LA
0 0
Sioux Falls, SD South Bend-Mishawaka, IN-MI
0 0
Spartanburg, SC Spokane, WA
0 0
Springfield, IL Springfield, MA-CT
0 0
Springfield, MO Springfield, OH
0 0
St. Cloud, MN St. Louis, MO-IL
0 0
Stockton, CA Syracuse, NY
0 0
Tallahassee, FL Toledo, OH
0 0
Topeka, KS Tucson, AZ
0 0
Tulsa, OK Tuscaloosa, AL
0 0
Utica-Rome, NY Valdosta, GA
0 0
Vallejo-Fairfield, CA Vero Beach, FL
0 0
Victoria, TX Vineland-Millville-Bridgeton, NJ
0 0
Visalia-Porterville, CA Waco, TX
0 0
Warner Robins, GA Waterloo-Cedar Falls, IA
0 0
Wausau, WI Winston-Salem, NC
0 0
Worcester, MA-CT Yakima, WA
0 0
York-Hanover, PA Youngstown-Warren-Boardman, OH
0 0
#Boston-Cambridge-Quincy, MA-NH
In Somalia?
sort(tapply(CPS$Country == "Somalia", CPS$MetroArea, sum, na.rm=TRUE),TRUE)
Minneapolis-St Paul-Bloomington, MN-WI Phoenix-Mesa-Scottsdale, AZ
17 7
Seattle-Tacoma-Bellevue, WA St. Cloud, MN
7 7
Columbus, OH Fargo, ND-MN
5 5
Burlington-South Burlington, VT Portland-South Portland, ME
3 3
Portland-Vancouver-Beaverton, OR-WA Houston-Baytown-Sugar Land, TX
3 2
Sioux Falls, SD Dayton, OH
2 1
Richmond, VA Akron, OH
1 0
Albany, GA Albany-Schenectady-Troy, NY
0 0
Albuquerque, NM Allentown-Bethlehem-Easton, PA-NJ
0 0
Altoona, PA Amarillo, TX
0 0
Anderson, IN Anderson, SC
0 0
Ann Arbor, MI Anniston-Oxford, AL
0 0
Appleton,WI Asheville, NC
0 0
Athens-Clark County, GA Atlanta-Sandy Springs-Marietta, GA
0 0
Atlantic City, NJ Augusta-Richmond County, GA-SC
0 0
Austin-Round Rock, TX Bakersfield, CA
0 0
Baltimore-Towson, MD Bangor, ME
0 0
Barnstable Town, MA Baton Rouge, LA
0 0
Beaumont-Port Author, TX Bellingham, WA
0 0
Bend, OR Billings, MT
0 0
Binghamton, NY Birmingham-Hoover, AL
0 0
Bloomington, IN Bloomington-Normal IL
0 0
Boise City-Nampa, ID Boston-Cambridge-Quincy, MA-NH
0 0
Boulder, CO Bowling Green, KY
0 0
Bremerton-Silverdale, WA Bridgeport-Stamford-Norwalk, CT
0 0
Brownsville-Harlingen, TX Buffalo-Niagara Falls, NY
0 0
Canton-Massillon, OH Cape Coral-Fort Myers, FL
0 0
Cedar Rapids, IA Champaign-Urbana, IL
0 0
Charleston, WV Charleston-North Charleston, SC
0 0
Charlotte-Gastonia-Concord, NC-SC Chattanooga, TN-GA
0 0
Chicago-Naperville-Joliet, IN-IN-WI Chico, CA
0 0
Cincinnati-Middletown, OH-KY-IN Cleveland-Elyria-Mentor, OH
0 0
Coeur d'Alene, ID Colorado Springs, CO
0 0
Columbia, MO Columbia, SC
0 0
Columbus, GA-AL Corpus Christi, TX
0 0
Dallas-Fort Worth-Arlington, TX Danbury, CT
0 0
Davenport-Moline-Rock Island, IA-IL Decatur, Al
0 0
Decatur, IL Deltona-Daytona Beach-Ormond Beach, FL
0 0
Denver-Aurora, CO Des Moines, IA
0 0
Detroit-Warren-Livonia, MI Dover, DE
0 0
Duluth, MN-WI Durham, NC
0 0
Eau Claire, WI El Centro, CA
0 0
El Paso, TX Erie, PA
0 0
Eugene-Springfield, OR Evansville, IN-KY
0 0
Farmington, NM Fayetteville, NC
0 0
Fayetteville-Springdale-Rogers, AR-MO Flint, MI
0 0
Florence, AL Fort Collins-Loveland, CO
0 0
Fort Smith, AR-OK Fort Walton Beach-Crestview-Destin, FL
0 0
Fort Wayne, IN Fresno, CA
0 0
Gainesville, FL Grand Rapids-Wyoming, MI
0 0
Greeley, CO Green Bay, WI
0 0
Greensboro-High Point, NC Greenville, SC
0 0
Gulfport-Biloxi, MS Hagerstown-Martinsburg, MD-WV
0 0
Harrisburg-Carlisle, PA Harrisonburg, VA
0 0
Hartford-West Hartford-East Hartford, CT Hickory-Morgantown-Lenoir, NC
0 0
Holland-Grand Haven, MI Honolulu, HI
0 0
Huntington-Ashland, WV-KY-OH Huntsville, AL
0 0
Indianapolis, IN Iowa City, IA
0 0
Jackson, MI Jackson, MS
0 0
Jacksonville, FL Jacksonville, NC
0 0
Janesville, WI Johnson City, TN
0 0
Johnstown, PA Joplin, MO
0 0
Kalamazoo-Portage, MI Kankakee-Bradley, IL
0 0
Kansas City, MO-KS Killeen-Temple-Fort Hood, TX
0 0
Kingsport-Bristol, TN-VA Kingston, NY
0 0
Knoxville, TN La Crosse, WI
0 0
Lafayette, LA Lake Charles, LA
0 0
Lakeland-Winter Haven, FL Lancaster, PA
0 0
Lansing-East Lansing, MI Laredo, TX
0 0
Las Cruses, NM Las Vegas-Paradise, NV
0 0
Lawrence, KS Lawton, OK
0 0
Leominster-Fitchburg-Gardner, MA Lexington-Fayette, KY
0 0
Little Rock-North Little Rock, AR Longview, TX
0 0
Los Angeles-Long Beach-Santa Ana, CA Louisville, KY-IN
0 0
Lubbock, TX Lynchburg, VA
0 0
Macon, GA Madera, CA
0 0
Madison, WI McAllen-Edinburg-Pharr, TX
0 0
Medford, OR Memphis, TN-MS-AR
0 0
Merced, CA Miami-Fort Lauderdale-Miami Beach, FL
0 0
Michigan City-La Porte, IN Midland, TX
0 0
Milwaukee-Waukesha-West Allis, WI Mobile, AL
0 0
Modesto, CA Monroe, LA
0 0
Monroe, MI Montgomery, AL
0 0
Muskegon-Norton Shores, MI Myrtle Beach-Conway-North Myrtle Beach, SC
0 0
Napa, CA Naples-Marco Island, FL
0 0
Nashville-Davidson-Murfreesboro, TN New Haven, CT
0 0
New Orleans-Metairie-Kenner, LA New York-Northern New Jersey-Long Island, NY-NJ-PA
0 0
Niles-Benton Harbor, MI Norwich-New London, CT-RI
0 0
Ocala, FL Ocean City, NJ
0 0
Ogden-Clearfield, UT Oklahoma City, OK
0 0
Olympia, WA Omaha-Council Bluffs, NE-IA
0 0
Orlando, FL Oshkosh-Neenah, WI
0 0
Oxnard-Thousand Oaks-Ventura, CA Palm Bay-Melbourne-Titusville, FL
0 0
Panama City-Lynn Haven, FL Pensacola-Ferry Pass-Brent, FL
0 0
Peoria, IL Philadelphia-Camden-Wilmington, PA-NJ-DE
0 0
Pittsburgh, PA Port St. Lucie-Fort Pierce, FL
0 0
Poughkeepsie-Newburgh-Middletown, NY Prescott, AZ
0 0
Providence-Fall River-Warwick, MA-RI Provo-Orem, UT
0 0
Pueblo, CO Punta Gorda, FL
0 0
Racine, WI Raleigh-Cary, NC
0 0
Reading, PA Reno-Sparks, NV
0 0
Riverside-San Bernardino, CA Roanoke, VA
0 0
Rochester, NY Rochester-Dover, NH-ME
0 0
Rockford, IL Sacramento-Arden-Arcade-Roseville, CA
0 0
Saginaw-Saginaw Township North, MI Salem, OR
0 0
Salinas, CA Salisbury, MD
0 0
Salt Lake City, UT San Antonio, TX
0 0
San Diego-Carlsbad-San Marcos, CA San Francisco-Oakland-Fremont, CA
0 0
San Jose-Sunnyvale-Santa Clara, CA San Luis Obispo-Paso Robles, CA
0 0
Santa Barbara-Santa Maria-Goleta, CA Santa Fe, NM
0 0
Santa Rosa-Petaluma, CA Santa-Cruz-Watsonville, CA
0 0
Sarasota-Bradenton-Venice, FL Savannah, GA
0 0
Scranton-Wilkes Barre, PA Shreveport-Bossier City, LA
0 0
South Bend-Mishawaka, IN-MI Spartanburg, SC
0 0
Spokane, WA Springfield, IL
0 0
Springfield, MA-CT Springfield, MO
0 0
Springfield, OH St. Louis, MO-IL
0 0
Stockton, CA Syracuse, NY
0 0
Tallahassee, FL Tampa-St. Petersburg-Clearwater, FL
0 0
Toledo, OH Topeka, KS
0 0
Trenton-Ewing, NJ Tucson, AZ
0 0
Tulsa, OK Tuscaloosa, AL
0 0
Utica-Rome, NY Valdosta, GA
0 0
Vallejo-Fairfield, CA Vero Beach, FL
0 0
Victoria, TX Vineland-Millville-Bridgeton, NJ
0 0
Virginia Beach-Norfolk-Newport News, VA-NC Visalia-Porterville, CA
0 0
Waco, TX Warner Robins, GA
0 0
Washington-Arlington-Alexandria, DC-VA-MD-WV Waterbury, CT
0 0
Waterloo-Cedar Falls, IA Wausau, WI
0 0
Wichita, KS Winston-Salem, NC
0 0
Worcester, MA-CT Yakima, WA
0 0
York-Hanover, PA Youngstown-Warren-Boardman, OH
0 0