1. Home
  2. FACUNIQUE procedure

FACUNIQUE procedure

Redefines a factor so that its levels and labels are unique (R.W. Payne).

Options

MERGESAME = string tokens What must be the same for groups defined by the factor to be merged (levels, labels); default * i.e. no groups are merged
INCREMENT = scalar Value to use to modify duplicate levels; default * i.e. a suitable (small) value is determined automatically
ADDTO = string token Whether to add the increment to the value or the absolute value of duplicated levels (value, absolutevalue); default abso

Parameters

OLDFACTOR = factors Factors whose levels and labels are to be made unique
NEWFACTOR = factors New factors with unique levels; if unset, the original OLDFACTOR is redefined
CHANGED = scalars Indicates whether the factor has changed

Description

FACUNIQUE allows you to correct mistakes in the definition of a factor that may have caused the same level number or the same label to occur more than once. Genstat does not fault duplicate levels or labels as there are some occasions when this may be deliberate. For example, you might want to use the same labelling for more than one line of a table, and might therefore have that label repeated in the factor classifying its rows.

The factors to correct are listed by the OLDFACTOR parameter, and the NEWFACTOR parameter can save the redefined factors. If no NEWFACTOR is defined for one of the factors in the OLDFACTOR list, the original factor itself is redefined. The CHANGED parameter can save a scalar that set to one if changes were needed, or otherwise set to zero.

By default, FACUNIQUE appends the characters '_1', '_2' and so on to each duplicate label. The default for levels is that it adds a small increment to each zero or positive duplicate level, and subtracts that increment from each negative duplicate level. If you would prefer to add the increment to both positive and negative levels, you can set option ADDTO=value. (This indicates that the increment is to be added to the value, rather than the absolute value of the duplicate level.) The default increment is taken as the largest power of 10 that is small enough to modify each duplicate level while preserving their numerical order. So, for example, if you had levels 1, 2, 3, 2, 5 and 2, the increment would be 0.1; the second instance of 2 would become 2.1, and the third would become 2.2. As another example, if the levels were 0.1, 0.2, 0.3, 0.2, 0,5 and 0.2, the increment would be 0.01; the second instance of 0.2 would then become 0.21, and the third would become 0.22. Alternatively, the INCREMENT option allows you to supply your own increment.

The MERGESAME option allows you to merge some of the groups that are defined by the factor. If you set MERGESAME=levels, any groups that have the same level will be merged (but any duplicate labels will still be made unique). If you set MERGESAME=labels, any groups that have the same label will be merged (but any duplicate levels will still be made unique). Finally, if you set MERGESAME=labels,levels, only groups that have the same level and label will be merged (but any remaining duplicate levels or labels will be made unique).

Options: MERGESAME, INCREMENT, ADDTO.

Parameters: OLDFACTOR, NEWFACTOR, CHANGED.

Method

The unique levels and labels are obtained using procedure FUNIQUEVALUES.

Action with RESTRICT

Any restrictions are ignored.

See also

Procedures: FACAMEND, FACEXCLUDEUNUSED, FACLEVSTANDARDIZE, FACSORT, FUNIQUEVALUES, FDISTINCTFACTORS.
Commands for: Calculations and manipulation.

Example

CAPTION    'FACUNIQUE example'; STYLE=meta
VARIATE    [VALUES=-3,-2,-1,0,1,2,3,4,0,1,-1,5] levs
TEXT       [VALUES=Z,Y,X,A,B,C,D,E,A,B,XX,E] labs
FACTOR     [NVALUES=24; LEVELS=levs; LABELS=labs] f1
GENERATE   f1

CAPTION    'Make levels and labels unique.'
FACUNIQUE  f1; NEWFACTOR=nf1
PRINT      3(f1,nf1); FREP=ordinals,levels,labels; FIELD=8; DECIMALS=1

CAPTION    'Merge labels and make levels unique.'
FACUNIQUE  [MERGESAME=labels] f1; NEWFACTOR=nf1
PRINT      3(f1,nf1); FREP=ordinals,levels,labels; FIELD=8; DECIMALS=1

CAPTION    'Merge levels and make labels unique.'
FACUNIQUE  [MERGESAME=levels] f1; NEWFACTOR=nf1
PRINT      3(f1,nf1); FREP=ordinals,levels,labels; FIELD=8; DECIMALS=1

CAPTION    'Merge when levels and labels same, otherwise make unique.'
FACUNIQUE  [MERGESAME=labels,levels] f1; NEWFACTOR=nf1
PRINT      3(f1,nf1); FREP=ordinals,levels,labels; FIELD=8; DECIMALS=1

Updated on September 2, 2019

Was this article helpful?