Bookmark and Share

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

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

st: using foreach and encode together

From   Tim Evans <>
To   "''" <>
Subject   st: using foreach and encode together
Date   Thu, 7 Jun 2012 09:57:08 +0100

Hi all,

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

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?

Any help gratefully received.

Best wishes

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:

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