Question 1.
> x <- c(5, 10, 15, 20, 25, 30)
> y <- c(-1, NA, 75, 3, 5, 8)
> z <- c(5)
Question 2
> a <- x*z
> b <- y*z
> print(a)
[1] 25 50 75 100 125 150
> print(b)
[1] -5 NA 375 15 25 40
Question 3
> library(haven)
> library(readr)
> setwd("C:/Users/drayr/OneDrive/Desktop/DEM Fall 2020/STATS 7273")
> stata <- read_dta("Data/stata_PSID_w1.dta")
> ##view the data*
> View(stata)
> ##select variables into a new data set*
> assignment1<-subset(x=stata,select=c("id","age","marpi","adjwlth2","educ","pubhs","h_race_ethnic_new","race5"))
> dim(assignment1)
[1] 131361 8
Question 3.1
> dim(assignment1)
[1] 131361 8
> str(assignment1)
tibble [131,361 x 8] (S3: tbl_df/tbl/data.frame)
$ id : num [1:131361] 4003 4003 4003 4003 4003 ...
..- attr(*, "format.stata")= chr "%9.0g"
$ age : num [1:131361] 49 51 53 55 57 59 47 49 51 53 ...
..- attr(*, "label")= chr "Age of respondent"
..- attr(*, "format.stata")= chr "%8.0g"
$ marpi : num [1:131361] 1 1 1 1 1 1 0 0 0 0 ...
..- attr(*, "label")= chr "Marital pairs indicator"
..- attr(*, "format.stata")= chr "%8.0g"
$ adjwlth2 : num [1:131361] 113 119 116 129 112 ...
..- attr(*, "label")= chr "Wealth (including home equity) in 1000s of yr 2000 "
..- attr(*, "format.stata")= chr "%9.0g"
$ educ : num [1:131361] 9 9 9 9 9 10 12 12 12 12 ...
..- attr(*, "label")= chr "Years completed education"
..- attr(*, "format.stata")= chr "%9.0g"
$ pubhs : num [1:131361] 0 0 0 0 0 0 0 0 0 0 ...
..- attr(*, "label")= chr "1 = lives in public housing"
..- attr(*, "format.stata")= chr "%8.0g"
$ h_race_ethnic_new: chr [1:131361] "NL White" "NL White" "NL White" "NL White" ...
..- attr(*, "label")= chr "Race/ethnicity updated codes (5/26/14)"
..- attr(*, "format.stata")= chr "%16s"
$ race5 : dbl+lbl [1:131361] 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, ...
..@ label : chr "Race/ethnicity updated codes (5/26/14)"
..@ format.stata: chr "%16.0g"
..@ labels : Named num [1:5] 1 2 3 4 5
.. ..- attr(*, "names")= chr [1:5] "Latino- Any Race" "NL Asian" "NL Black" "NL Other" ...
> print(assignment1)
# A tibble: 131,361 x 8
id age marpi adjwlth2 educ pubhs h_race_ethnic_new race5
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <dbl+lbl>
1 4003 49 1 113. 9 0 NL White 5 [NL White]
2 4003 51 1 119. 9 0 NL White 5 [NL White]
3 4003 53 1 116. 9 0 NL White 5 [NL White]
4 4003 55 1 129. 9 0 NL White 5 [NL White]
5 4003 57 1 112. 9 0 NL White 5 [NL White]
6 4003 59 1 104. 10 0 NL White 5 [NL White]
7 4004 47 0 493 12 0 NL White 5 [NL White]
8 4004 49 0 447. 12 0 NL White 5 [NL White]
9 4004 51 0 386. 12 0 NL White 5 [NL White]
10 4004 53 0 2493. 12 0 NL White 5 [NL White]
# ... with 131,351 more rows
Question 3.2
> hist(assignment1$race5)

Question 3.3
> mean(assignment1$adjwlth2,na.rm = T)
[1] 187.1656
> median(assignment1$adjwlth2,na.rm = T)
[1] 32.804
Question 3.4
> min(assignment1$age)
[1] 1
> max(assignment1$age)
[1] 999
> IQR(assignment1$age)
[1] 33
> mean(assignment1$age)
[1] 32.02676
> median(assignment1$age)
[1] 29
Question 3.5
> table(assignment1$pubhs)
0 1
124366 6961
> # 6961 people received public assistance in the form of public housing.
> newdata<- subset(x=assignment1,pubhs==1, select = all())
> table(newdata$race5)
1 2 3 4 5
366 27 5472 114 982
> table(newdata$h_race_ethnic_new)
Latino- Any Race NL Asian NL Black NL Other
366 27 5472 114
NL White
982
> # 366 Latinos received public assistance in the form of public housing.
>
> newdata$race5<-factor(newdata$race5,
+ levels = c(1,2,3,4,5),
+ labels=c("Latino","Asian","Black","Other","White"))
> prop.table(table(newdata$race5))
Latino Asian Black Other White
0.052578652 0.003878753 0.786093952 0.016376957 0.141071685
> table(newdata$race5)
Latino Asian Black Other White
366 27 5472 114 982
Question 3.6
> # I would be interested to know information about individuals' parents characteristics such as, Parent education attainment and Parent level of income and Geographic information to compare demographic structures across geographies.