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: using foreach and encode together
From
Tim Evans <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
RE: st: using foreach and encode together
Date
Thu, 7 Jun 2012 14:09:30 +0100
Thanks Nick for your help,
I've changed the length of my variable name and all is fine!
Best wishes
Tim
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 07 June 2012 10:08
To: [email protected]
Subject: Re: st: using foreach and encode together
The variable name
IntegrTNM_Stage_Algo_No_assumpti
is already 32 characters long, so you can't prepend "v2" to get
another variable name. You have to shorten it.
I would -drop- only if the -encode- works. If the -encode- fails then
it's true that the loop would stop, as here, but in general watch out
that you might lose the variable.
if _rc == 0 drop `var'
Nick
On Thu, Jun 7, 2012 at 9:57 AM, Tim Evans <[email protected]> wrote:
> I'm trying to encode a number of string variables and generate new variables which contain the string values as labels. I have a number of these variables and am trying to avoid doing each manually, however, I am encountering some problems with the syntax. A quick google search has not yielded any answers for me. I'm using Stata 11.2.
>
> Here is my code:
>
> foreach var of varlist IntegrT_Stage_Algo Nodes_Positive IntegrTNM_Stage_Algo_No_assumpti InvStatus {
> encode `var', gen(v2`var')
> }
>
> this is my error message:
>
> option gen() incorrectly specified
> r(198);
>
> I guess what I would also like once I have generated the new variable, to drop the string version - perhaps I can add -drop `var'- after the -encode- line?
*
* 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/
_DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.
*
* 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/