help for checkvar

Produce a table showing the relationship between a created variable and its com > ponent variables

checkvar created-variable varlist [if] [in]


checkvar displays a table showing each value of a created variable, followed by each unique combination of values of the component variables and the frequency of each combination. The created-variable should be listed first after the command, then each component variable that was used to create it.

checkvar can also be used to examine patterns of respondents in a set of skip and filter questions in a survey. In this case the first substantive question following the skips and filters should be viewed as the created variable and the skips and filtes as the component variables.


This command is more useful if the created and component variables have few discrete values than if they have a large number of values.

Example - created variable

. sysuse auto

. gen byte goodcar=(rep78>=3 & headroom>3 & trunk>15)

. checkvar goodcar rep78 headroom trunk

. replace goodcar=. if rep78==.

. checkvar goodcar rep78 headroom trunk

Example - skip pattern

. checkvar q45 q40 q42 q43

Saved Results

If all variables in varlist are numeric, the checkvar command saves in r() (see help for return):

r(combos) - the number of combinations

r(checkvar) - the matrix of all combinations and their frequencies


Dan Blanchette and Nick Cox suggested very useful improvements to this command.


Phil Bardsley, Carolina Population Center, University of North Carolina - Chapel Hill, USA. Contact phil_bardsley@unc.edu if you observe any problems.

Also see

Manual: [R] tabulate, [R] table, [R] contract

Online: help for tabulate, table, contract; groups (if installed)