Skip to contents

Create a new variable which is an interaction of two other variables. Also see tab_cross().

Usage

var_cross(newvr, vr, vrby)

Arguments

newvr

name of the new variable to be created

vr

first variable

vrby

second variable

Value

Survey object

See also

Other variables: var_all(), var_any(), var_case(), var_collapse(), var_copy(), var_cut(), var_not()

Examples

set_survey(namcs2019sv)
#>                         Survey info {NAMCS 2019 PUF}                         
#> ┌───────────┬──────────────┬────────────────────────────────────────────────┐
#> │ Variables │ Observations │ Design                                         │
#> ├───────────┼──────────────┼────────────────────────────────────────────────┤
#> │        33 │        8,250 │ Stratified 1 - level Cluster Sampling design   │
#> │           │              │ (with replacement)                             │
#> │           │              │ With (398) clusters.                           │
#> │           │              │ namcs2019sv = survey::svydesign(ids = ~CPSUM,  │
#> │           │              │ strata = ~CSTRATM, weights = ~PATWT            │
#> │           │              │ , data = namcs2019sv_df)                       │
#> └───────────┴──────────────┴────────────────────────────────────────────────┘
#> 
var_cross("Age x Sex", "AGER", "SEX")
tab("Age x Sex")
#>                               Age x Sex (knowns only) {NAMCS 2019 PUF}                              
#> ┌─────────────┬───────┬─────────────┬──────────┬──────────┬──────────┬─────────┬─────┬──────┬──────┐
#> │ Level       │     n │      Number │ SE (000) │ LL (000) │ UL (000) │ Percent │  SE │   LL │   UL │
#> │             │       │       (000) │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ Under 15    │   434 │      59,958 │    7,206 │   47,318 │   75,974 │     5.8 │ 0.7 │  4.5 │  7.3 │
#> │ years:      │       │             │          │          │          │         │     │      │      │
#> │ Female      │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 15-24       │   346 │      41,128 │    4,532 │   33,066 │   51,156 │     4   │ 0.4 │  3.2 │  4.9 │
#> │ years:      │       │             │          │          │          │         │     │      │      │
#> │ Female      │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 25-44       │   923 │     113,708 │   11,461 │   93,256 │  138,646 │    11   │ 1   │  9   │ 13.2 │
#> │ years:      │       │             │          │          │          │         │     │      │      │
#> │ Female      │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 45-64       │ 1,253 │     175,978 │   16,009 │  147,153 │  210,450 │    17   │ 1.1 │ 14.8 │ 19.3 │
#> │ years:      │       │             │          │          │          │         │     │      │      │
#> │ Female      │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 65-74       │   891 │     120,099 │   11,066 │  100,171 │  143,992 │    11.6 │ 1   │  9.7 │ 13.7 │
#> │ years:      │       │             │          │          │          │         │     │      │      │
#> │ Female      │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 75 years    │   762 │      94,173 │   11,085 │   74,682 │  118,751 │     9.1 │ 0.9 │  7.3 │ 11.1 │
#> │ and over:   │       │             │          │          │          │         │     │      │      │
#> │ Female      │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ Under 15    │   453 │      57,959 │    7,728 │   44,570 │   75,371 │     5.6 │ 0.7 │  4.3 │  7.2 │
#> │ years: Male │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 15-24       │   196 │      23,728 │    4,344 │   16,457 │   34,210 │     2.3 │ 0.4 │  1.6 │  3.2 │
#> │ years: Male │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 25-44       │   512 │      56,562 │    7,277 │   43,861 │   72,942 │     5.5 │ 0.6 │  4.3 │  6.8 │
#> │ years: Male │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 45-64       │ 1,030 │     133,528 │   12,956 │  110,319 │  161,619 │    12.9 │ 1   │ 10.9 │ 15.1 │
#> │ years: Male │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 65-74       │   770 │      86,766 │    6,767 │   74,409 │  101,176 │     8.4 │ 0.6 │  7.2 │  9.7 │
#> │ years: Male │       │             │          │          │          │         │     │      │      │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 75 years    │   680 │      72,896 │    6,661 │   60,872 │   87,296 │     7   │ 0.6 │  5.9 │  8.3 │
#> │ and over:   │       │             │          │          │          │         │     │      │      │
#> │ Male        │       │             │          │          │          │         │     │      │      │
#> └─────────────┴───────┴─────────────┴──────────┴──────────┴──────────┴─────────┴─────┴──────┴──────┘
#>   N = 8250. Checked NCHS presentation standards. Nothing to report.                                 
#>