help joinvars -------------------------------------------------------------------------------
Title
joinvars -- Join values of variables
Syntax
joinvars newvar [=] varlist [if] [in] [, options]
options Description ------------------------------------------------------------------------- update replace non-missing values with non-missing values missok replace non-missing values with missing values -------------------------------------------------------------------------
Description
joinvars creates variable newvar containing joined values of varlist. Starting with a copy of the first variable in varlist, missing values in newvar are replaced with values of the next variable(s) in varlist.
Options
+---------+ ----+ Options +----------------------------------------------------------
update replaces non-missing values in newvar with values of variables in varlist. Default is to replace missing values only.
missok replaces non-missing values in newvar with missing values of variables in varlist. May only be specified with update.
Example
First, I separate wages by race in the NLSW 1988 dataset using separate.
. sysuse nlsw88 ,clear (NLSW, 1988 extract)
. separate wage ,by(race)
[output omitted]
Now suppose the original variable wage is missing in this dataset. It can be created using joinvars.
. drop wage
. list race wage* in 516/520
+----------------------------------------+ | race wage1 wage2 wage3 | |----------------------------------------| 516. | white 4.428341 . . | 517. | white 15.09662 . . | 518. | black . 6.843801 . | 519. | other . . 6.513685 | 520. | white 5.072463 . . | +----------------------------------------+
. joinvars wage = wage1 wage2 wage3
. list race wage1 wage2 wage3 wage in 516/520
+---------------------------------------------------+ | race wage1 wage2 wage3 wage | |---------------------------------------------------| 516. | white 4.428341 . . 4.428341 | 517. | white 15.09662 . . 15.09662 | 518. | black . 6.843801 . 6.843801 | 519. | other . . 6.513685 6.513685 | 520. | white 5.072463 . . 5.072463 | +---------------------------------------------------+
The options
. joinvars nonsense = wage1 wage2 wage3 ,update missok
. list race wage1 wage2 wage3 nonsense in 516/520
+---------------------------------------------------+ | race wage1 wage2 wage3 nonsense | |---------------------------------------------------| 516. | white 4.428341 . . . | 517. | white 15.09662 . . . | 518. | black . 6.843801 . . | 519. | other . . 6.513685 6.513685 | 520. | white 5.072463 . . . | +---------------------------------------------------+
Author
Daniel Klein, University of Bamberg, klein.daniel.81@gmail.com
Also see
Online: separate, egen, reshape