Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: RE: looping through vectors


From   Ernest Berkhout <[email protected]>
To   [email protected]
Subject   Re: st: RE: RE: looping through vectors
Date   Wed, 28 May 2003 13:38:18 +0200

Patrick,

I think you're doing exactly the opposite of what you intended to do in the 3rd statement. You are copying the old values into the new ones (you replace `new' with 'old')



At 13:12 28-5-2003, Patrick wrote:

Nick

thanks for your help. I'm running your second option for irregular suffixes
and, although I don't seem to be getting error messages, it isn't working.
The first vector comprises variables:

rpy204 rpy203 rpy199 rpy206 rpy210 rpy202 rpy014 rpy207 rpy209 rpy013 rpy201
rpy200 rpy018 rpy016 rpy017

the second vector comprises:

_rpy204 _rpy203 _rpy199 _rpy206_rpy210 _rpy202 _rpy014 _rpy207 _rpy209
_rpy013 _rpy201 _rpy200 _rpy018 _ rpy016 _rpy017

I have written the following code which produces the output as shown (note
that I'm also including an if command as I only want to copy over values
conditional on the value of additional variable). The values of the
variables in the first vector (or set) remain uncyhanged when I tab them.
Any ideas?

Patrick

. foreach v of var rpy* {
2.         local new : subinstr local   v       "rpy"   "_rpy"
3.         replace `new' = `v'
4. } if show3 == 1
Ernest Berkhout
SEO Amsterdam Economics
University of Amsterdam

Room 3.08
Roetersstraat 29
1018 WB Amsterdam
The Netherlands

tel.:+ 31 20 525 1657
fax:+ 31 20 525 1686
http://www.seo.nl
===========================
A statistician: someone who insists
on being certain about uncertainty
===========================

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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