Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Cox <[email protected]> |

To |
"'[email protected]'" <[email protected]> |

Subject |
RE: st: replacement |

Date |
Tue, 16 Aug 2011 15:11:15 +0100 |

This is not a reasonable thing to do in the sense that the same variable cannot be both numeric and string. However, you could fix that by e.g. replace v`y'= "1" if v`y'=="a" I think my suggestion is still valid. Nick [email protected] Gannaway Jack WWG HWWD Thanks for the reply. I realise I may not have made myself very clear. I am not trying to change the labels, but rather the actual content of the variable. My original table is effectively categorical (a,b,c,d). However, rather than simply using something like this: Forvalues y=1/3 { Replace v`y'=1 if v`y'=="a" Replace v`y'=2 if v`y'=="b" ... } Which has as many scores as letters (4 in the example below), I want to replace the letters with scores which are specific to Y, meaning you have up to 3 x 4 scores in this example. I know this is something which is fairly reasonable to do, but I was just wondering if there was a way of doing it which would minimise the opportunity for human error if the scores change (which they will!). Nick Cox -label define- followed by -encode-. On Tue, Aug 16, 2011 at 9:59 AM, Gannaway Jack WWG HWWD <[email protected]> wrote: > I have a table where each observation has a letter as the value for a > number of the variables, e.g. > > Ob v1 v2 v3 > 1 a a b > 2 c d a > 3 b c b > > > For each variable, there is a unique set of numbers which correspond > to the letters: > > Var a b c d > V1 0 3 5 9 > V2 0 1 2 5 > V3 0 1 5 10 > > Can anyone explain a neat way of replacing all the letters with their > relevent numeric score? I know I could just do a messy and long > replace, but the score table is liable to change in the future and I > want a system where I can just point to a different input, rather than > manually re-write the replace command. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**Re: st: replacement***From:*Nick Cox <[email protected]>

**RE: st: replacement***From:*"Gannaway Jack WWG HWWD" <[email protected]>

- Prev by Date:
**RE: st: Programming Stata** - Next by Date:
**Re: st: replacement** - Previous by thread:
**RE: st: replacement** - Next by thread:
**Re: st: replacement** - Index(es):