Created
March 11, 2016 16:55
-
-
Save jakeesse/8b651feefae96a8d9c51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setwd('/users/JakeEsse/Desktop/HIST 90') | |
library(readr) | |
library(dplyr) | |
library(ggplot2) | |
library(scales) | |
library(grid) | |
family_master_data <- read_csv('usa_00012.csv') | |
a <- family_master_data | |
b <- mutate(a, sex=factor(SEX, labels = c('male','female'))) | |
head(b) | |
c <- filter(b, AGE>14, MARST<6, NCHILD>0) | |
head(c) | |
d <- mutate(c, marst=factor(ifelse(MARST==2, 1, MARST), labels = c('Married','Separated', 'Divorced', 'Widowed'))) | |
head(d) | |
ee <- mutate(d, weight=ifelse(YEAR==1950, SLWT, PERWT)) | |
head(ee) | |
e <- mutate(ee, income=ifelse(INCWAGE==999999, 0, INCWAGE)) | |
head(e) | |
f <- mutate(e, nchild=factor(ifelse(NCHILD>5, 6, NCHILD), labels = c('1', '2', '3', '4', '5', '6+'))) | |
head(f) | |
g <- filter(f, EMPSTAT==1) | |
head(g) | |
h <- summarize(group_by(g, YEAR, sex, marst), inc=median(rep(income, times=weight))) | |
head(h) | |
years <- c(1940, 1950, 1960, 1970, 1980, 1990, 2000, 2010) | |
index <- c(15.58, 9.05, 7.37, 5.62, 2.65, 1.67, 1.27, 1) | |
cpi <- as.data.frame(cbind(years,index)) | |
print(cpi) | |
i <- merge(h, cpi, by.x='YEAR', by.y='years') | |
head(i) | |
j <- ggplot(i, aes(x=YEAR, y=inc*index, color=marst))+geom_line()+geom_point()+facet_grid(.~sex)+labs(title='Median Wage Income, Inflation Adjusted', x='year', y='dollars') | |
print(j) | |
k <- filter(g, MARST<5 & MARST!=3) | |
l <- summarize(group_by(k, YEAR, sex, marst, nchild), inc=median(rep(income, times=weight))) | |
head(l) | |
m <- merge(l, cpi, by.x='YEAR', by.y='years') | |
head(m) | |
n <- ggplot(m, aes(x=YEAR, y=inc*index, color=marst))+geom_line()+geom_point()+facet_grid(nchild~.~sex)+labs(title='Median Wage Income, Inflation Adjusted', x='year', y='dollars') | |
print(n) | |
o <- summarize(group_by(k, YEAR, sex, marst, nchild), NUMBER=sum(weight)) | |
head(o) | |
p <- ggplot(o, aes(x=YEAR, y=NUMBER, fill=nchild)) + geom_bar(stat='identity', position = 'fill')+facet_grid(sex~.~marst) + scale_fill_brewer(palette = 'Set3') + guides(fill=guide_legend(reverse=TRUE,title='Children')) + labs(title='Number of Children by Sex and Marital Status', x='Year', y='Number') + scale_y_continuous(labels=scales::percent) | |
print(p) | |
q <- filter(k, NCHILD>3) | |
r <- summarize(group_by(q, YEAR, sex, marst, nchild), NUMBER=sum(weight)) | |
head(r) | |
s <- ggplot(r, aes(x=YEAR, y=NUMBER, fill=nchild)) + geom_bar(stat='identity', position = 'fill')+facet_grid(sex~.~marst) + scale_fill_brewer(palette = 'Set3') + guides(fill=guide_legend(reverse=TRUE,title='Children')) + labs(title='Number of Children by Sex and Marital Status', x='Year', y='Number') + scale_y_continuous(labels=scales::percent) | |
print(s) | |
ll <- summarize(group_by(q, YEAR, sex, marst, nchild), inc=median(rep(income, times=weight))) | |
head(ll) | |
mm <- merge(ll, cpi, by.x='YEAR', by.y='years') | |
head(mm) | |
nn <- ggplot(mm, aes(x=YEAR, y=inc*index, color=marst))+geom_line()+geom_point()+facet_grid(nchild~.~sex)+labs(title='Median Wage Income, Inflation Adjusted', x='year', y='dollars') | |
print(nn) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment