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

RE: st: AW: Merging database

From   "Nick Cox" <>
To   <>
Subject   RE: st: AW: Merging database
Date   Wed, 29 Apr 2009 19:29:28 +0100

I can reconcile the apparent difference. 

Eric is lucky that both -recode- and -tostring- accept varlists with

However, note that -foreach- in his code is _not_ setting up a loop over
the variables implied by the wildcard. 

Rather, -foreach- is looping once, over its single item -V*-. 

So, my initial criticism was wrong in so far as Eric's code will work,
but perhaps not for the reason he thought. 


Nick Cox

Well, it does not work for me. (I do know what a wildcard like V* means
in Stata. The point is that you need -of var- to make explicit that you
have one.) 

. clear

. set obs 1
obs was 0, now 1

. gen v1 = 1

. gen v2 = 2

. gen v3 = 3

. foreach v in V* {
  2. d `v'
  3. }
variable V* not found


Eric A. Booth

On Apr 29, 2009, at 12:03 PM, Nick Cox wrote:

> I have various comments on this code.
> 1. -foreach x in V*- won't work. Eric is probably thinking of
> -foreach x of var V*- but in this case -foreach v in V1 V2 V3- takes  
> no more thought.

-foreach x in V*- works for fine for me.  It loops over all the  
variables V1-V3.

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index