Lab report

download.file("https://github.com/angelaxocampo/SSM/raw/main/Lab_3/lab3.Rmd", destfile = "lab3.Rmd")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(haven)
library(forcats)
LNS <-read_dta(url("https://github.com/angelaxocampo/SSM/raw/main/Lab_1/Data/LNS.dta"))
LNS %>% 
  count(PARBORN) %>% 
  mutate(pct = prop.table(n) * 100)
## # A tibble: 5 × 3
##   PARBORN                                 n    pct
##   <dbl+lbl>                           <int>  <dbl>
## 1 1 [One parent born in the U.S.]       700  8.11 
## 2 2 [Both parents born in the U.S.]    1803 20.9  
## 3 3 [Neither parent born in the U.S.]  6015 69.7  
## 4 4 [Don't Know]                         87  1.01 
## 5 5 [Refused]                            29  0.336
LNS %>% 
  count(PARBORN) %>% 
  mutate(pct = prop.table(n) * 100)  %>% 
  ggplot(aes(x = PARBORN, y = pct)) + 
    geom_col() +
  xlab("Parents birth place") + ylab("Percentage") +
  theme(axis.text.x = element_text(angle=45, vjust = .5))

LNS %>% 
  count(GRANBORN) %>% 
  mutate(pct = prop.table(n) * 100) %>% 
  ggplot(aes(x = GRANBORN, y = pct)) + 
    geom_col() +
  xlab("Grandparents birth place") + ylab("Percentage")+
  theme(axis.text.x = element_text(angle=45, vjust = .5))

LNS <- LNS %>%  
  mutate(PARENTS_BIRTHPLC = 
           case_when(PARBORN == 1 ~ "One parent born in the U.S.",
                     PARBORN == 2 ~ "Both parents born in the U.S.",
                     PARBORN == 3 ~ "Neither parent born in the U.S.",
                     PARBORN == 4 ~ "DK/Refused",
                     PARBORN == 5 ~ "DK/Refused"),
         PARENTS_BIRTHPLC = factor(PARENTS_BIRTHPLC, 
                            levels =  c("One parent born in the U.S.", 
                                        "Both parents born in the U.S.",
                                        "Neither parent born in the U.S.",
                                        "DK/Refused")))
LNS %>% 
  count(PARENTS_BIRTHPLC) %>%
  mutate(pct = prop.table(n) * 100)  %>% 
  ggplot(aes(x = PARENTS_BIRTHPLC, y = pct)) + 
    geom_col() +
  xlab("Parents birth place") + ylab("Percentage")

LNS <- LNS %>% 
  mutate(GENDER = 
         case_when(SEX == 1 ~ "Male",
                   SEX == 2 ~ "Female"))
LNS %>% 
  group_by(GENDER) %>% 
  count(PARENTS_BIRTHPLC) %>%
  mutate(pct = prop.table(n) * 100)  %>% 
  ggplot(aes(x = PARENTS_BIRTHPLC, y = pct, fill=GENDER)) + 
    geom_col(position = "dodge") +
  xlab("Parents birth place") + ylab("Percentage")

LNS <- LNS %>% 
  mutate(GENERATION = 
         case_when(BORNUS == 1 & PARBORN == 1 ~ "Second",
                   BORNUS == 1 & PARBORN == 2 ~ "Third +",
                   BORNUS == 1 & PARBORN == 3 ~ "Second",
                   BORNUS == 1 & PARBORN == 4 ~ "NA",
                   BORNUS == 1 & PARBORN == 5 ~ "NA",
                   BORNUS == 2 & PARBORN == 1 ~ "Second",
                   BORNUS == 2 & PARBORN == 2 ~ "Third +",
                   BORNUS == 2 & PARBORN == 3 ~ "Second",
                   BORNUS == 2 & PARBORN == 4 ~ "Second",
                   BORNUS == 2 & PARBORN == 5 ~ "Second",
                   BORNUS == 3 ~ "First"),
         GENERATION = factor(GENERATION,
                             levels = c("First", "Second", "Third +", "NA")))
LNS %>% 
  count(GENERATION) %>%
  mutate(pct = prop.table(n) * 100)
## # A tibble: 4 × 3
##   GENERATION     n    pct
##   <fct>      <int>  <dbl>
## 1 First       5717 66.2  
## 2 Second      1865 21.6  
## 3 Third +     1024 11.9  
## 4 NA            28  0.324
first.gen  <- LNS  %>%
  filter(GENERATION == "First")
first.gen %>% 
  filter(AGE < 35) %>% 
  group_by(GENDER) %>% 
  count()
## # A tibble: 2 × 2
## # Groups:   GENDER [2]
##   GENDER     n
##   <chr>  <int>
## 1 Female  1206
## 2 Male    1060
LNS %>% 
  count(BIGINTST) %>% 
   mutate(p = prop.table(n) * 100)
## # A tibble: 5 × 3
##   BIGINTST                  n     p
##   <dbl+lbl>             <int> <dbl>
## 1 1 [Strongly disagree]  1142  13.2
## 2 2 [Somewhat disagree]  1196  13.9
## 3 3 [Somewhat agree]     2124  24.6
## 4 4 [Strongly agree]     3201  37.1
## 5 9 [DK/NA]               971  11.2
LNS %>% 
  count(BIGINTST) %>% 
  mutate(p = prop.table(n) * 100)
## # A tibble: 5 × 3
##   BIGINTST                  n     p
##   <dbl+lbl>             <int> <dbl>
## 1 1 [Strongly disagree]  1142  13.2
## 2 2 [Somewhat disagree]  1196  13.9
## 3 3 [Somewhat agree]     2124  24.6
## 4 4 [Strongly agree]     3201  37.1
## 5 9 [DK/NA]               971  11.2
s.e. = sqrt(.371*(1-.371)/8634)

lower_co  = .371 - 1.96 * s.e.
upper_co =  .371 + 1.96 * s.e.

lower_co
## [1] 0.3608103
upper_co
## [1] 0.3811897

On your own:

1: 1A) According to the data given it seems as though many immigrants came to the US to improve their financial situations. 1B) I did not see many differences in reasoning for men or women to come to the United States. Both groups are just trying to make a better life for not only themeselves but their family as well, along with having financial opportunities unlike most of their native countries.

2: I did not see many differences in the opinions between these two groups. They all beleive and want the best for the children and do not think that even though they are undocumented they should not have to pay more.

3: According to my calculations around 43% of Latinos/Hispanics in the United States believe that they are treated fairly by police. This does surprise me because I thought that the number would be much higher given the time that this survey takes place.