For strata defined by multiple variables (e.g. sex,age,country) one combined variable is generated.

generateStrata(df, stratavars, name)

Arguments

df

a data.frame

stratavars

character vector with variable name

name

name of the newly generated variable

Value

The original data set with one new column.

Author

Alexander Kowarik

Examples


x <- testdata
x <- generateStrata(x,c("sex","urbrur"),"strataIDvar")
head(x)
#>   urbrur roof walls water electcon relat sex age hhcivil   expend   income
#> 1      2    4     3     3        1     1   1  46       2 90929693 57800000
#> 2      2    4     3     3        1     2   2  41       2 27338058 25300000
#> 3      2    4     3     3        1     3   1   9       1 26524717 69200000
#> 4      2    4     3     3        1     3   1   6       1 18073948 79600000
#> 5      2    4     2     3        1     1   1  52       2  6713247 90300000
#> 6      2    4     2     3        1     2   2  47       2 49057636 32900000
#>     savings ori_hid sampling_weight household_weights strataIDvar
#> 1  116258.5       1             100          25.00000         1-2
#> 2  279345.0       1             100          25.00000         2-2
#> 3 5495381.0       1             100          25.00000         1-2
#> 4 8695862.0       1             100          25.00000         1-2
#> 5  203620.2       2             100          16.66667         1-2
#> 6 1021268.0       2             100          16.66667         2-2