Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 122
---
title: "Addhealth 4 data" author: "Esteban Gonzales" date: "02/12/2020"
---

In this file I selected my variables for my research

The first thing I did was load in the dyplyr and janitor commands. This will allow me to use the pipe tool which I will use later to plug in my variables.

library(dplyr) library(janitor)

The second thing I did was load in the raw data using the load command

load("~/Data/addhealth4.RData")

The next thing to do is to load in the ls command in order to find out what the data is called.

ls()

Once that has been done, the next step is to load in the variables I wanted to change

To do that I first put in mydata and then adhealth because my data is in there. Then I used the pipe tool and from there I selected the variables I wanted to enter.

mydata <- addhealth4 %>% select(H4LM14, H4LM17, H4LM13, H4LM12)

From here the next step was to change the values of the categorical variables. I did that by mutating and recoding the old variables so that I could replace them with the new ones.

After I finished mutating the variables I deleted the old ones by using select so that only the new ones would stay.

clean <- mydata %>% select(H4LM17, H4LM14, H4LM13, H4LM12) %>% mutate(new_H4LM14 = recode(H4LM14, "8" = "keeping house", "10" = "other", "97" = "legitimate skip", "4" = "permanently sick", "5" = "unemployed and looking for work")) %>% mutate(new_H4LM17 = recode(H4LM17, "7" = "pregnancy or family reasons", "97" = "legitimate skip", "4" = "discharged or fired", "2" = "plant closed", "6" = "health problems", "3" = "end of temporary job")) %>% select(-H4LM17, -H4LM14)

Then I cleaned the data. For that I used the clean command.

clean

The last thing I did was do tables for my variables. I used the tabyl command.

clean %>% tabyl(new_H4LM14)

This table shows percentages and numbers for what people are doing at the time. Like are they looking for work, keeping house, or are they permanently sick etc.

clean %>% tabyl(new_H4LM17)

This table shows reasons people left their main job.

clean %>% tabyl(H4LM13)

This table shows how many hours people spend at the jobs they're working at.

clean %>% tabyl(H4LM12)

This table shows how many jobs a person is currently working for that pays at least 10 hours a week.

The final step is to save the clean data.

save(clean, file="~/Data/addhealth4_clean.RData")