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]

st: Creating macro varlist for loop - different outcomes with different methods?


From   Felix Acker <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Creating macro varlist for loop - different outcomes with different methods?
Date   Mon, 23 Dec 2013 05:04:16 +0000

Hello All,

I have encountered a problem in running a loop on a varlist. My dataset consists of 112 variables, nearly all of them have unique names. I would like to assign them to macros in blocks, for example variable 15 (name = weight) to variable 20 (name = abstinence). I would then like to run a loop on this varlist, using a very basic command such as 'tab' and am expecting separate tables for each variable. When I individually type the variable names for the varlist: 

local TableItems Weight LGA TypeOfWork PosInLocal Aware Abstinence 
foreach x in `TableItems' { 
tab `x', sort 
}

This works just fine. 
However, when I use the hyphen method to create the varlist, the variables seem to be bound different, in that I get an error message for more than two variables, and a two-way table if my varlist consists of two variables only.

local TableItems Weight-Abstinence
foreach x in `TableItems' {
tab `x', sort
}

Would anyone happen to know why this occurs, and how to get around it? In the case of 5 variables, it is easy enough to type them out, but it surely should be possible to do this more efficiently.

Thanks for your help and best from Melbourne,
Felix Acker

Dr Felix Acker
Senior Project Officer
Knowledge and Environments for Health
Victorian Health Promotion Foundation (VicHealth)
15-31 Pelham Street  Carlton  Victoria  3053
IMPORTANT - This email, including all attachments, may be confidential. If you are not the intended recipient, you must not disclose, distribute, copy or use the information contained in this email or attachments. Any confidentiality or privilege is not waived or lost because this email has been sent to you in error. If you have received it in error, please let us know by reply email, or telephone us on (613) 96671333, delete it from your system and destroy any copies. Any representations or opinions expressed in this email are those of the individual sender, and not necessarily those of the Victorian Health Promotion Foundation.


SPAM DISCLAIMER - VicHealth utilises spam filtering software on our email server. Users acknowledge that while every effort is made to ensure the filtering service operates optimally, it is possible that the SPAM filtering software may inadvertently block an otherwise legitimate email. If you have not received a response to an email you’ve sent after 2 days, we recommend you call our office on (61 3) 9667 1333 to confirm receipt.



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