.- help for ^swapval^ .-Swapping values of two variables --------------------------------

^swapval^ avar bvar { ^if^ exp | ^in^ list_of_obs }

Description -----------

^swapval^ interchanges the values of avar and bvar, so long as both variables are numeric or both are string.

Remarks -------

^swapval^ may be useful whenever data checking suggests that values for two variables have been interchanged. In simple cases, this calls for a few ^replace^ statements, or the use of the data editor (under Windows or Macintosh), but in other cases a single command may be useful.

^swapval^ can be applied unconditionally, in which case it is in essence

^tempname copy^ ^rename^ bvar ^`copy'^ ^rename^ avar bvar ^rename `copy'^ avar

Alternatively, it can be applied conditionally, using either ^if^ or ^in^, but not both. Note that ^in^ list_of_obs is more general than the usual ^in^ range. The list_of_obs can be any integer numlist specifying observation numbers, including numbers from ^1^ to _N or from ^-1^ to ^-^_N, provided that _N is replaced by the actual number. ^f^ and ^l^ for first and last observation are also indulged.

Examples --------

In a data set ^max^ should always be not less than ^min^. A check shows that this is not true in two observations, 42 and 666. If we suppose that this must be a data error, then it can be fixed by

. ^swapval min max in 42 666^

or

. ^swapval min max if max < min^

Author ------

Nicholas J. Cox, University of Durham, U.K. n.j.cox@@durham.ac.uk

Also see --------

On-line: help for @replace@, @edit@ (Windows or Macintosh)