# Survey of Health, Ageing and Retirement in Europe (SHARE)

The Survey of Health, Ageing and Retirement in Europe interviews senior citizens across the continent for their entire life. Allows for findings like, “Among Belgians who were 50-74 years old in 2004, X% lived in nursing homes by 2010.”

Many tables, most with one row per sampled respondent for the period.

A complex sample longitudinal survey designed to generalize to the civilian, non-institutionalized population of participating European countries aged 50 or older.

Released every two or three years since 2004.

Coordinated at the Max Planck Institute and funded by consortium.

## Simplified Download and Importation

The R `lodown`

package easily downloads and imports all available SHARE microdata by simply specifying `"share"`

with an `output_dir =`

parameter in the `lodown()`

function. Depending on your internet connection and computer processing speed, you might prefer to run this step overnight.

```
library(lodown)
lodown( "share" , output_dir = file.path( path.expand( "~" ) , "SHARE" ) ,
your_username = "username" ,
your_password = "password" )
```

`lodown`

also provides a catalog of available microdata extracts with the `get_catalog()`

function. After requesting the SHARE catalog, you could pass a subsetted catalog through the `lodown()`

function in order to download and import specific extracts (rather than all available extracts).

```
library(lodown)
# examine all available SHARE microdata files
share_cat <-
get_catalog( "share" ,
output_dir = file.path( path.expand( "~" ) , "SHARE" ) ,
your_username = "username" ,
your_password = "password" )
# wave 1, wave 6, and longitudinal weights only
share_cat <- subset( share_cat , grepl( "ave 1|ave 6|ongitudinal" , output_folder ) )
# download the microdata to your local computer
share_cat <- lodown( "share" , share_cat ,
your_username = "username" ,
your_password = "password" )
```

## Analysis Examples with the `survey`

library

Construct a complex sample survey design:

```
options( survey.lonely.psu = "adjust" )
library(survey)
available_files <-
list.files(
file.path( path.expand( "~" ) , "SHARE" ) ,
recursive = TRUE ,
full.names = TRUE
)
# wave six demographics file
share_dn6_df <-
readRDS( grep( "6\\.0\\.0(.*)sharew6(.*)dn\\.rds" , available_files , value = TRUE ) )
share_dn6_df <-
share_dn6_df[ c( "mergeid" , "country" , "dn042_" , "dn004_" ) ]
# wave six physical health file
share_ph1_df <-
readRDS( grep( "sharew1(.*)ph\\.rds" , available_files , value = TRUE ) )
share_ph1_df$weight_in_2004 <-
ifelse( share_ph1_df$ph012_ < 0 , NA , share_ph1_df$ph012_ )
share_ph1_df <-
share_ph1_df[ c( "mergeid" , "weight_in_2004" , "ph005_" ) ]
# wave six physical health file
share_ph6_df <-
readRDS( grep( "6\\.0\\.0(.*)sharew6(.*)ph\\.rds" , available_files , value = TRUE ) )
share_ph6_df$weight_in_2015 <-
ifelse( share_ph6_df$ph012_ < 0 , NA , share_ph6_df$ph012_ )
share_ph6_df <-
share_ph6_df[ c( "mergeid" , "weight_in_2015" , "ph003_" ) ]
# longitudinal weights file
share_longwt_df <-
readRDS( grep( "longitudinal_weights_w1\\-(.*)\\.rds" , available_files , value = TRUE ) )
# france only longitudinal weights
france_df <- subset( share_longwt_df , country == 17 & ( cliw_a > 0 ) )
nrow_check <- nrow( france_df )
# merge on each of the tables
france_df <- merge( france_df , share_dn6_df )
france_df <- merge( france_df , share_ph1_df )
france_df <- merge( france_df , share_ph6_df )
# confirm no change in records
stopifnot( nrow( france_df ) == nrow_check )
share_design <-
svydesign(
~ psu + ssu ,
strata = ~ stratum1 + stratum2 ,
data = france_df ,
weights = ~ cliw_a ,
nest = TRUE
)
```

### Variable Recoding

Add new columns to the data set:

```
share_design <-
update(
share_design ,
one = 1 ,
sexe = factor( dn042_ , levels = 1:2 , labels = c( 'masculin' , 'feminin' ) ) ,
health_in_general_2015 =
factor( ph003_ , levels = 1:5 , labels =
c( "excellente" , "tres bonne" , "bonne" , "acceptable" , "mediocre" )
) ,
fortemente_limite_2004 = ifelse( ph005_ %in% 1:3 , as.numeric( ph005_ == 1 ) , NA )
)
```

### Unweighted Counts

Count the unweighted number of records in the survey sample, overall and by groups:

```
sum( weights( share_design , "sampling" ) != 0 )
svyby( ~ one , ~ sexe , share_design , unwtd.count )
```

### Weighted Counts

Count the weighted size of the generalizable population, overall and by groups:

```
svytotal( ~ one , share_design )
svyby( ~ one , ~ sexe , share_design , svytotal )
```

### Descriptive Statistics

Calculate the mean (average) of a linear variable, overall and by groups:

```
svymean( ~ weight_in_2015 , share_design , na.rm = TRUE )
svyby( ~ weight_in_2015 , ~ sexe , share_design , svymean , na.rm = TRUE )
```

Calculate the distribution of a categorical variable, overall and by groups:

```
svymean( ~ health_in_general_2015 , share_design , na.rm = TRUE )
svyby( ~ health_in_general_2015 , ~ sexe , share_design , svymean , na.rm = TRUE )
```

Calculate the sum of a linear variable, overall and by groups:

```
svytotal( ~ weight_in_2015 , share_design , na.rm = TRUE )
svyby( ~ weight_in_2015 , ~ sexe , share_design , svytotal , na.rm = TRUE )
```

Calculate the weighted sum of a categorical variable, overall and by groups:

```
svytotal( ~ health_in_general_2015 , share_design , na.rm = TRUE )
svyby( ~ health_in_general_2015 , ~ sexe , share_design , svytotal , na.rm = TRUE )
```

Calculate the median (50th percentile) of a linear variable, overall and by groups:

```
svyquantile( ~ weight_in_2015 , share_design , 0.5 , na.rm = TRUE )
svyby(
~ weight_in_2015 ,
~ sexe ,
share_design ,
svyquantile ,
0.5 ,
ci = TRUE ,
keep.var = TRUE ,
na.rm = TRUE
)
```

Estimate a ratio:

```
svyratio(
numerator = ~ weight_in_2015 ,
denominator = ~ weight_in_2004 ,
share_design ,
na.rm = TRUE
)
```

### Subsetting

Restrict the survey design to persons born in france:

`sub_share_design <- subset( share_design , dn004_ == 1 )`

Calculate the mean (average) of this subset:

`svymean( ~ weight_in_2015 , sub_share_design , na.rm = TRUE )`

### Measures of Uncertainty

Extract the coefficient, standard error, confidence interval, and coefficient of variation from any descriptive statistics function result, overall and by groups:

```
this_result <- svymean( ~ weight_in_2015 , share_design , na.rm = TRUE )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
svyby(
~ weight_in_2015 ,
~ sexe ,
share_design ,
svymean ,
na.rm = TRUE
)
coef( grouped_result )
SE( grouped_result )
confint( grouped_result )
cv( grouped_result )
```

Calculate the degrees of freedom of any survey design object:

`degf( share_design )`

Calculate the complex sample survey-adjusted variance of any statistic:

`svyvar( ~ weight_in_2015 , share_design , na.rm = TRUE )`

Include the complex sample design effect in the result for a specific statistic:

```
# SRS without replacement
svymean( ~ weight_in_2015 , share_design , na.rm = TRUE , deff = TRUE )
# SRS with replacement
svymean( ~ weight_in_2015 , share_design , na.rm = TRUE , deff = "replace" )
```

Compute confidence intervals for proportions using methods that may be more accurate near 0 and 1. See `?svyciprop`

for alternatives:

```
svyciprop( ~ fortemente_limite_2004 , share_design ,
method = "likelihood" , na.rm = TRUE )
```

### Regression Models and Tests of Association

Perform a design-based t-test:

`svyttest( weight_in_2015 ~ fortemente_limite_2004 , share_design )`

Perform a chi-squared test of association for survey data:

```
svychisq(
~ fortemente_limite_2004 + health_in_general_2015 ,
share_design
)
```

Perform a survey-weighted generalized linear model:

```
glm_result <-
svyglm(
weight_in_2015 ~ fortemente_limite_2004 + health_in_general_2015 ,
share_design
)
summary( glm_result )
```

## Analysis Examples with `srvyr`

The R `srvyr`

library calculates summary statistics from survey data, such as the mean, total or quantile using dplyr-like syntax. srvyr allows for the use of many verbs, such as `summarize`

, `group_by`

, and `mutate`

, the convenience of pipe-able functions, the `tidyverse`

style of non-standard evaluation and more consistent return types than the `survey`

package. This vignette details the available features. As a starting point for SHARE users, this code replicates previously-presented examples:

```
library(srvyr)
share_srvyr_design <- as_survey( share_design )
```

Calculate the mean (average) of a linear variable, overall and by groups:

```
share_srvyr_design %>%
summarize( mean = survey_mean( weight_in_2015 , na.rm = TRUE ) )
share_srvyr_design %>%
group_by( sexe ) %>%
summarize( mean = survey_mean( weight_in_2015 , na.rm = TRUE ) )
```