On Wed, Feb 1, 2023 at 9:03 AM Cottrell, Allin <cottrell(a)wfu.edu> wrote:
On Wed, Feb 1, 2023 at 5:02 AM Paolo Chirico <paolo.chirico(a)uniupo.it> wrote:
>
> Dears,
> If I have a string variable with the following mapping:
> 1 = 'middle'
> 2 = 'low'
> 3 = 'high'
> there is a command to give the series a new, more logical mapping? Like as:
> 1 = 'low'
> 2 = 'middle'
> 3 = 'high'
> I've simplified the example, but the concept is: changing the numerical
> mapping of the entire series
[...]
While my previous answer works for the simplified case, it may be
worth giving a more general, automated solution. Here's a function
that does the job:
<hansl>
function void recode (series *y, series x, strings S)
y = 0
matrix m = {y}
strings S0 = x
loop i=1..nelem(S)
matrix sel = instrings(S0, S[i])
m[sel] = i
endloop
y = m
stringify(y, S)
end function
</hansl>
The idea is that you pass (1) a target series in pointer form, (2) the
original string-valued series and (3) an array holding the string
values of the original series, re-ordered as per the desired numerical
coding. So in relation to my previous example you'd do:
<caller>
open strs.csv
series y
recode(&y, x, defarray("low", "middle", "high"))
</caller>
Allin