Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: problem creating and doing a foreach on a local of all numeric variables in a dataset


From   Maarten buis <[email protected]>
To   [email protected]
Subject   RE: st: problem creating and doing a foreach on a local of all numeric variables in a dataset
Date   Wed, 27 Aug 2008 16:09:44 +0100 (BST)

--- "Jennifer S. Earl" <[email protected]> wrote:
> Just so I understand, though, I'll ask a follow-up:
> Let's say I wanted to name the initial list of numeric variables
> something different than the initial list of string variables (hence
> me trying to put them in the local macros num_list and string_list)
> so I could use these lists at different points later in the program
> and the lists would not be affected by subsequently created variables
> (as they would if I just remade the lists each time).
> 
> Right now, I could not do this because both the numeric and string
> lists both appear to be called `r(varlist)' ; the contents just got
> replaced by running "ds , has(type numeric)" or "ds , has(type
> string)" right before the foreach loop.
> 
> How could I save off those initial lists and then later successfully 
> operate on them in a foreach loop?

ds , has(type numeric)
local num_list "`r(varlist)'"
ds , has(type string)
local string_list "`r(varlist)'"

do other stuff

foreach var of varlist `num_list' {
    do numeric stuff
}

foreach var of varlist `string_list' {
    do string stuff
}

Hope this helps,
Maarten



-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

Send instant messages to your online friends http://uk.messenger.yahoo.com 
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index