Bookmark and Share

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]

RE: st: replacement


From   "Gannaway Jack WWG HWWD" <[email protected]>
To   <[email protected]>
Subject   RE: st: replacement
Date   Tue, 16 Aug 2011 14:51:27 +0100

Nick,

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!).

Many thanks.

Jack 


	-------------------------------------------------------------------------------------------------------
      Jack Gannaway 
        Economic Adviser |  Department for Work & Pensions, Caxton House, Tothill Street, London, SW1H 9D
        [email protected] | Tel: 02074 495704 (x 65704) 





-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 16 August 2011 10:19
To: [email protected]
Subject: Re: st: replacement


-label define- followed by -encode-.

Nick

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/
**********************************************************************

This document is strictly confidential and is intended only for use by the addressee. 

If you are not the intended recipient, any disclosure, copying, distribution or other 

action taken in reliance of the information contained in this e-mail is strictly prohibited.

Any views expressed by the sender of this message are not necessarily those of the Department 

for Work and Pensions.

If you have received this transmission in error, please use the reply function to tell us 

and then permanently delete what you have received.

This email was scanned for viruses by the Department for Work and Pensions' anti-virus services and on leaving the Department was found to be virus free.

Please note: Incoming and outgoing e-mail messages are routinely monitored for compliance 

with our policy on the use of electronic communications.

**********************************************************************


*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index