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

st: RE: RE: modification on <renpfix>?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: modification on <renpfix>?
Date   Mon, 6 Dec 2004 23:46:23 -0000

Strictly the -foreach- examples do what 
you want if and only if the quoted string
occurs as a suffix and not otherwise. 

For example, 

_ja_ja 

would get renamed to 

_1_ja 

by the first loop. 

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Nick Cox
> Sent: 06 December 2004 23:09
> To: [email protected]
> Subject: st: RE: modification on <renpfix>?
> 
> 
> Yes. -rensfix- by Stephen Jenkins and myself 
> is a deliberately created sibling (STB-59). 
> 
> A more general command yet capable of doing 
> this, what -renpfix- does, and much more is 
> -renvars- from Jeroen Weesie and myself 
> (STB-60). 
> 
> Having said that, minimalists and despisers 
> of ad hoc tools would want to mention the 
> use of -foreach- here: 
> 
> foreach v of var *_ja { 
> 	local new : subinstr local v "_ja" "_1"' 
> 	rename `v' `new' 
> } 
> 
> or 
> 
> foreach v of var *_ja { 
> 	rename `v' `: subinstr local v "_ja" "_1"' 
> } 
> 
> Similarly, 
> 
> foreach v of var *_fe { 
> 	rename `v' `: subinstr local v "_ja" "_2"' 
> } 
> 
> In other words, you can knit your own replacements
> in one move on the fly. 
> 
> Jeroen Weesie I think has mixed feelings about
> -renvars- given the existence of -foreach-. 
> I feel somewhat the same way, but guess that there 
> are users who might like -renvars- but 
> who draw the line at working out their own macro 
> manipulations each time they have problems like this. 
> 	
> Nick 
> [email protected] 
> 
> Danielle Ferry
> 
> > Is there a command similar to <renpfix> where instead it 
> renames all 
> > variables that END with old_stub to END with new_stub? If not, can 
> > anyone suggest a  relatively easy way of doing this for a 
> > large number 
> > of variables that all end with the same stub? I.e., I want 
> to rename 
> > everything *_ja to *_1 and everything *_fe to *_2, etc. Thanks.
> 
> *
> *   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/
> 

*
*   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