mkdir /storage01/projects/add_health/data/marissa

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(haven)
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2.2. https://CRAN.R-project.org/package=stargazer
library(survey)
## Loading required package: grid
## Loading required package: Matrix
## Loading required package: survival
## 
## Attaching package: 'survey'
## The following object is masked from 'package:graphics':
## 
##     dotchart
library(questionr)
library(haven)
df1<- read_dta("/projects/add_health/data/11613344/ICPSR_27021/DS0001/da27021p1.dta")
df1w <- read_dta("/projects/add_health/data/11613344/ICPSR_27021/DS0025/da27021p25.dta")
wv1 <- merge(df1, df1w, by="aid")
save(wv1, file = "/projects/add_health/data/marissa/waveI.Rdata")
load("/projects/add_health/data/marissa/waveI.Rdata")
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode

Recoding variables

table(wv1$H1SU1)
## 
##     0     1     6     8     9 
## 17753  2748   159    81     4
wv1$suicidethought<-recode(wv1$H1SU1, recodes="0=0; 1=1; 6=NA; 8=NA; 9=NA")
  is.numeric(wv1$suicidethought)                        
## [1] TRUE
table(wv1$suicidethought)
## 
##     0     1 
## 17753  2748
wv1$suicideattempt<-recode(wv1$H1SU2, recodes="0=0; 1:4=1; 6=NA;7=NA; 8=NA; 9=NA")
  is.numeric(wv1$suicideattempt)                        
## [1] TRUE
table(wv1$suicideattempt)
## 
##    0    1 
## 1937  806
wv1$grade<-Recode(wv1$H1GI20, recodes="7=7; 8=8; 9=9; 10=10; 11=11; 12=12; else=NA")
table(wv1$grade)
## 
##    7    8    9   10   11   12 
## 2716 2718 3620 3967 3809 3356
table(wv1$H1GI20)
## 
##    7    8    9   10   11   12   96   97   98   99 
## 2716 2718 3620 3967 3809 3356    3  408    8  140
table(wv1$H1GI4)
## 
##     0     1     6     8 
## 17158  3525     8    54
wv1$hispanic<-Recode(wv1$H1GI4, recodes="0=0; 1=1; else=NA")
table(wv1$hispanic)
## 
##     0     1 
## 17158  3525
table(wv1$BIO_SEX)
## 
##     1     2     6     8 
## 10263 10480     1     1
wv1$sex<-Recode(wv1$BIO_SEX, recodes="1=1; 2=0; else=NA")
table(wv1$sex)
## 
##     0     1 
## 10480 10263
table(wv1$H1TO15)
## 
##    1    2    3    4    5    6    7   96   97   98 
##  213  497 1318 1618 2494 3506 1921   20 9136   22
wv1$alcohol<-Recode(wv1$H1TO15, recodes="1=7; 2=6; 3=5; 4=4; 5=3; 6=2; 7=1; else=NA")
table(wv1$alcohol)
## 
##    1    2    3    4    5    6    7 
## 1921 3506 2494 1618 1318  497  213
wv1$alcohol2<-Recode(wv1$alcohol, recodes="1=0; 2=1; 3=2; 4=3; 5=4; 6=5; 7=6; as.numeric; else=NA")
table(wv1$alcohol2)
## 
##    0    1    2    3    4    5    6 
## 1921 3506 2494 1618 1318  497  213
table(wv1$H1TO32)
## 
##     0     1     2     3     4     5     6     7     8     9    10    11    12 
##  2786   757   430   273   154   215    66    46    34    23   132    11    40 
##    13    14    15    16    17    18    19    20    21    22    23    24    25 
##     6    13   103     3     4     4     8   132     1     5     9     3    68 
##    26    27    28    29    30    33    34    35    36    37    39    40    43 
##    10     5    20     9   162     4     1     8     1     1     2    23     2 
##    44    45    47    50    56    60    65    67    70    75    80    90    92 
##     1    12     1    24     1    27     1     1     5     5     5     5     1 
##    99   100   111   120   130   150   200   300   350   400   420   500   530 
##     4    29     2     1     1     2     2     2     1     1     1     2     1 
##   534   554   666   800   899   900   996   997   998   999 
##     1     1     2     1     1     1   205 14605   203    13
wv1$pot<-Recode(wv1$H1TO32, recodes="996:999=NA")
table(wv1$pot)
## 
##    0    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15 
## 2786  757  430  273  154  215   66   46   34   23  132   11   40    6   13  103 
##   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   33 
##    3    4    4    8  132    1    5    9    3   68   10    5   20    9  162    4 
##   34   35   36   37   39   40   43   44   45   47   50   56   60   65   67   70 
##    1    8    1    1    2   23    2    1   12    1   24    1   27    1    1    5 
##   75   80   90   92   99  100  111  120  130  150  200  300  350  400  420  500 
##    5    5    5    1    4   29    2    1    1    2    2    2    1    1    1    2 
##  530  534  554  666  800  899  900 
##    1    1    1    2    1    1    1
table(wv1$H1FS6)
## 
##     0     1     2     3     6     8 
## 12338  6192  1539   624    25    27
wv1$depressed<-Recode(wv1$H1FS6, recodes="6=NA; 8=NA")
table(wv1$depressed)
## 
##     0     1     2     3 
## 12338  6192  1539   624
table(wv1$H1SU4)
## 
##     0     1     6     8     9 
## 16903  3551   145   143     3
table(wv1$H1SU6)
## 
##     0     1     6     8     9 
## 19557   926   137   122     3
wv1$friendattempt<-Recode(wv1$H1SU4, recodes="0=0; 1=1; else=NA")
wv1$familyattempt<-Recode(wv1$H1SU6, recodes="0=0; 1=1; else=NA")
table(wv1$friendattempt)
## 
##     0     1 
## 16903  3551
table(wv1$familyattempt)
## 
##     0     1 
## 19557   926
table(wv1$H1HS3)
## 
##     0     1     6     8 
## 18133  2556    24    32
table(wv1$H1HS1)
## 
##     0     1     6     8 
##  7351 13321    19    54
wv1$counseling<-Recode(wv1$H1HS3, recodes="0=0; 1=1; else=NA")
wv1$routineexam<-Recode(wv1$H1HS1, recodes="0=0; 1=1; else=NA")
table(wv1$counseling)
## 
##     0     1 
## 18133  2556
table(wv1$routineexam)
## 
##     0     1 
##  7351 13321
table(wv1$PA57D)
## 
##     0     1     6 
## 15071  2278    60
wv1$foodstamp<-Recode(wv1$PA57D, recodes="0=0; 1=1; else=NA")
table(wv1$foodstamp)
## 
##     0     1 
## 15071  2278
table(wv1$H1NM7)
## 
##     0     1     6     7     8 
##   229  2526     3 17983     4
wv1$biomom<-Recode(wv1$H1NM7, recodes="0=0; 1=1; else=NA")
table(wv1$biomom)
## 
##    0    1 
##  229 2526
table(wv1$H1NF7)
## 
##     0     1     6     7     8 
##  1627  5544     2 13549    23
wv1$biodad<-Recode(wv1$H1NF7, recodes="0=0; 1=1; else=NA")
table(wv1$biodad)
## 
##    0    1 
## 1627 5544

Neighborhood Variables

table(wv1$H1NB2)
## 
##     1     2     6     8     9 
## 16147  4479    63    55     1
wv1$talkneighbor<-Recode(wv1$H1NB2, recodes="2=0; 1=1; else=NA")
table(wv1$talkneighbor)
## 
##     0     1 
##  4479 16147
table(wv1$H1NB4)
## 
##     0     1     6     8     9 
## 16390  4210    64    76     5
wv1$reccenter<-Recode(wv1$H1NB4, recodes="0=0; 1=1; else=NA")
table(wv1$reccenter)
## 
##     0     1 
## 16390  4210
table(wv1$H1NB5)
## 
##     0     1     6     8 
##  2425 18182    65    73
wv1$feelsafe<-Recode(wv1$H1NB5, recodes="0=0; 1=1; else=NA")
table(wv1$feelsafe)
## 
##     0     1 
##  2425 18182
table(wv1$PA34)
## 
##     1     2     3     6 
## 10282  5339  1642   337
wv1$drugdealer<-Recode(wv1$PA34, recodes="1=0; 2=1; 3-2; else=NA")
table(wv1$drugdealer)
## 
##     0     1 
## 10282  5339

Family Support

table(wv1$H1WP17F)
## 
##     0     1     6     7     8     9 
## 11889  7570    16  1256    13     1
wv1$talkproblemmom<-Recode(wv1$H1WP17F, recodes="0=0; 1=1; else=NA")
table(wv1$talkproblemmom)
## 
##     0     1 
## 11889  7570
table(wv1$H1WP18F)
## 
##     0     1     6     7     8     9 
## 11477  2952    17  6282    15     2
wv1$talkproblemdad<-Recode(wv1$H1WP18F, recodes="0=0; 1=1; else=NA")
table(wv1$talkproblemdad)
## 
##     0     1 
## 11477  2952
table(wv1$H1WP17I)
## 
##     0     1     6     7     8     9 
## 16888  2571    16  1256    13     1
wv1$projectmom<-Recode(wv1$H1WP17I, recodes="0=0; 1=1; else=NA")
table(wv1$projectmom)
## 
##     0     1 
## 16888  2571
table(wv1$H1WP18I)
## 
##     0     1     6     7     8     9 
## 12858  1571    17  6282    15     2
wv1$projectdad<-Recode(wv1$H1WP18I, recodes="0=0; 1=1; else=NA")
table(wv1$projectdad)
## 
##     0     1 
## 12858  1571
hispaniconly = subset(wv1, hispanic==1)
save(wv1, file = "/storage01/projects/add_health/data/marissa/wv1b.Rdata")
load("/projects/add_health/data/marissa/wv1b.Rdata")