Skip to content

Commit

Permalink
Added final? IATRB models
Browse files Browse the repository at this point in the history
  • Loading branch information
c-voulgaris committed Jun 27, 2024
1 parent 5f0d0d2 commit c83d9a2
Show file tree
Hide file tree
Showing 58 changed files with 11,499 additions and 24 deletions.
Binary file added compare_nests.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 19 additions & 11 deletions data-assembly/survey-quintile-example.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,26 @@ hh_2017 <- here("nhts",
# filter rows with missing value for income
filter(income_k > 0) |>
# create survey object with weights
as_survey_design(weights = WTHHFIN) |>
# Calculate quintile thresholds
mutate(quint_break = survey_quantile(income_k,
quantiles = c(0.2,
0.4,
0.6,
0.8))) |>
as_survey_design(weights = WTHHFIN)
```


```{r}
threshholds <- survey::svyquantile(~income_k,
design = hh_2017,
quantiles = c(0.2, 0.4, 0.6, 0.8))
```


```{r}
hh_2017 <- hh_2017 |>
# compare income_k value to thresholds to get income quintile of each HH
mutate(inc_quint = case_when(income_k < quint_break$`_q20`[1] ~ "q1",
income_k < quint_break$`_q40`[1] ~ "q2",
income_k < quint_break$`_q60`[1] ~ "q3",
income_k < quint_break$`_q80`[1] ~ "q4",
mutate(inc_quint = case_when(income_k < threshholds$income_k[1] ~ "q1",
income_k < threshholds$income_k[2] ~ "q2",
income_k < threshholds$income_k[3] ~ "q3",
income_k < threshholds$income_k[4] ~ "q4",
TRUE ~ "q5"))
```

Expand Down
33 changes: 33 additions & 0 deletions data-assembly/upper-income-bin.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
library(tidyverse)
library(here)
library(srvyr)
library(survey)

ipums_data <- here("data",
"usa_00009.csv.gz") |>
read_csv() |>
filter(GQ != 3 & GQ != 4)

data_2009 <- ipums_data |>
filter(YEAR == 2009 & HHINCOME > 100000) |>
group_by(SERIAL) |>
summarise(CLUSTER = first(CLUSTER),
STRATA = first(STRATA),
HHWT = first(HHWT),
HHINCOME = first(HHINCOME)) |>
as_survey_design(ids = CLUSTER,
weights = HHWT)

survey::svyquantile(~HHINCOME, data_2009, 0.5)

data_2017 <- ipums_data |>
filter(YEAR == 2017 & HHINCOME > 200000) |>
group_by(SERIAL) |>
summarise(CLUSTER = first(CLUSTER),
STRATA = first(STRATA),
HHWT = first(HHWT),
HHINCOME = first(HHINCOME)) |>
as_survey_design(ids = CLUSTER,
weights = HHWT)

survey::svyquantile(~HHINCOME, data_2017, 0.5)
Loading

0 comments on commit c83d9a2

Please sign in to comment.