ACT-SCI-654-HW-11.pdf - ACT SCI 654 Homework#11 1 ACT SCI 654 HW 11 1 a MEPS<-read.csv"C\Users\22916\OneDrive\Documents\data\MyMEPS.csv MEPS < MEPS

ACT-SCI-654-HW-11.pdf - ACT SCI 654 Homework#11 1 ACT SCI...

This preview shows page 1 - 5 out of 14 pages.

ACT SCI 654 Homework #11 November 27, 2019 1
Image of page 1
ACT SCI 654 HW 11 1 a MEPS<- read.csv ( "C:\\Users\\22916\\OneDrive\\Documents\\data\\MyMEPS.csv" ) MEPS <- MEPS[ which (MEPS $ OBVEXP09 > 0 ), order ( colnames (MEPS))] # names(MEPS) dat <- MEPS[ , c ( "panel" , "sex" , "AGE09X" , "POVCAT09" , "educyr" , "OBVEXP09" , "racethnx" , "hispanx" , "PHYACT53" , ############## DATA CLEAN-UP ## change sex to numeric indicator variable for Male dat $ Male <- 1 * (dat $ sex == 1 ) ## re-code poverty cat FAMILY INC AS % OF POVERTY LINE dat <- within (dat,{ Poverty <- POVCAT09 # note need this statement to initialize the variable Poverty[POVCAT09 == 1 ] <- "Poor" Poverty[POVCAT09 == 2 ] <- "NearPoor" Poverty[POVCAT09 == 3 ] <- "LowInc" Poverty[POVCAT09 == 4 ] <- "MidInc" Poverty[POVCAT09 == 5 ] <- "HighInc" }) dat $ Poverty <- as.factor (dat $ Poverty) ## re-code data for educyr to missing dat <- within (dat,{ YearsEduc <- educyr # note need this statement to initialize the variable YearsEduc[YearsEduc == -9 ] <- NA YearsEduc[YearsEduc == -8 ] <- NA YearsEduc[YearsEduc == -7 ] <- NA YearsEduc[YearsEduc == -1 ] <- NA }) ## Look at Age dat <- within (dat,{ Age <- AGE09X # note need this statement to initialize the variable Age[AGE09X == -1 ] <- NA }) ## log-transforms dat $ log.OffExp <- log (dat $ OBVEXP09) ## Exercise > 5/week dat <- within (dat,{ Exercise <- PHYACT53 # note need this statement to initialize the variable Exercise[PHYACT53 == -9 ] <- NA Exercise[PHYACT53 == -8 ] <- NA Exercise[PHYACT53 == -7 ] <- NA Exercise[PHYACT53 == -1 ] <- NA Exercise[PHYACT53 == 1 ] <- "Yes" Exercise[PHYACT53 == 2 ] <- "No" }) dat $ Exercise <- as.factor (dat $ Exercise) dat $ FamilySize <- dat $ FAMSZE09 dat <- within (dat,{ SeatBelt <- SEATBE53 # note need this statement to initialize the variable SeatBelt[SEATBE53 == -8 ] <- NA SeatBelt[SEATBE53 == -7 ] <- NA SeatBelt[SEATBE53 == -1 ] <- NA 2
Image of page 2
ACT SCI 654 HW 11 SeatBelt[SEATBE53 == 1 | SEATBE53 == 2 | SEATBE53 == 6 ] <- "Yes" SeatBelt[SEATBE53 == 3 | SEATBE53 == 4 | SEATBE53 == 5 ] <- "No" }) dat <- within (dat,{ RaceEth <- racethnx # note need this statement to initialize the variable RaceEth[racethnx == 1 ] <- "Hispanic" RaceEth[racethnx == 2 ] <- "NonHispanic White" RaceEth[racethnx == 3 ] <- "NonHispanic Black" RaceEth[racethnx == 4 ] <- "NonHispanic Asian" RaceEth[racethnx == 5 ] <- "NonHispanic Other/Multiple" }) dat $ RaceEth <- factor (dat $ RaceEth) dat <- within (dat,{ Hispanic <- hispanx # note need this statement to initialize the variable Hispanic[hispanx == 1 ] <- "Hispanic" Hispanic[hispanx == 2 ] <- "Not Hispanic" }) dat $ Hispanic <- factor (dat $ Hispanic) ## Poverty category defined by % of Poverty Line dat <- within (dat,{ Poverty <- POVCAT09 # note need this statement to initialize the variable Poverty[POVCAT09 == 1 ] <- "Poor" ## less than 100% Poverty[POVCAT09 == 2 ] <- "Near Poor" ## between 100% and 125% Poverty[POVCAT09 == 3 ] <- "Low" ## between 125% and 200% Poverty[POVCAT09 == 4 ] <- "Middle" ## between 200% and 400% Poverty[POVCAT09 == 5 ] <- "High" ## greater than 400% }) dat $ Poverty <- factor (dat $ Poverty) dat <- within (dat,{ PovNP <- NA # note need this statement to initialize the variable PovNP[POVCAT09 == 1 ] <- "PoorOrNearPoor" ## less than 100% PovNP[POVCAT09 == 2 ] <- "PoorOrNearPoor" ## between 100% and 125% PovNP[POVCAT09 == 3 ] <- "Other" ## between 125% and 200% PovNP[POVCAT09 == 4 ] <- "Other" ## between 200% and 400% PovNP[POVCAT09 == 5 ] <- "Other" ## greater than 400% }) dat $ PovNP <- factor (dat $ PovNP, levels = c ( "PoorOrNearPoor" , "Other" )) 3
Image of page 3
ACT SCI 654 HW 11 ## Employment status dat <- within (dat,{ EmployRd31 <- NA # note need this statement to initialize the variable EmployRd31[EMPST31 == 1 ] <- "[email protected]" EmployRd31[EMPST31 == 2 ] <- "JobReturn" EmployRd31[EMPST31 == 3 ] <- "WillBeEmplDuringRound" EmployRd31[EMPST31 == 4 ] <- "UnEmployed" }) dat $ EmployRd31 <- factor (dat $ EmployRd31) dat <-
Image of page 4
Image of page 5

You've reached the end of your free preview.

Want to read all 14 pages?

  • Fall '19

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors