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]

From |
[email protected] |

To |
[email protected] |

Subject |
Re: st: Changing part of variable names |

Date |
Tue, 24 May 2011 15:56:02 +0200 |

Hi Nick, thanks for your reply. The problem is a bit more complicated. The issue is not that I have 11 files, but that I have some 400 variables in each file, each variable having a year tag at a random place in its name. Examples of variable names: permit09 , hab_ch09 , plingu09 , pdate09 , p09d160 , p09d161 , p09d162 . The "09" is the year tag, and I want to replace that with XX or somthing similar using a loop. I checked out the renvars package, but I don't see how I can avoid typing 400 variable names with it. Thanks, Frank -------- Original-Nachricht -------- > Datum: Tue, 24 May 2011 14:34:46 +0100 > Von: Nick Cox <[email protected]> > An: [email protected] > Betreff: Re: st: Changing part of variable names > Thanks for the mention. Note that -renvars- is a joint production by > Jeroen Weesie > and myself. > > However, in this case I don't see that you need anything other than > -rename-. > > Let's suppose that the files are called -file1- to -file11-. > > forval i = 1/11 { > use file`i' > rename income?? income > save, replace > } > > For a more complicated set of filenames, use e.g. -fs- (SSC) followed by > > foreach f in `r(files)' { > use "`f'" > ... > } > > > Nick > > On Tue, May 24, 2011 at 2:16 PM, Maarten Buis <[email protected]> > wrote: > > On Tue, May 24, 2011 at 2:27 PM, <[email protected]> wrote: > >> I have the following problem: I have 11 separate Stata-files, each > containing a cross-section for one specific year. The variables in each > corss-section are the same, except for the names, which carry a year tag in the > variable name, so there's e.g. income07 in the cross-section for 2007, and > income08 in the one for 2008. Now, I want to transform these 11 files into > one panel data set. Therefore, I need to rename the variables in each cross > section (several hundreds per cross-section) such that they have the same > name, i.e. income07 and income08 need to become incomeXX -otherwise "append" > wouldn't work. How do I do this with a loop? Further complication: the year > tag can be anywhere in the variable name, things like in07come, income07 > or inco07me are possible. > > > > The easiest solution is probably to use Nick Cox's -renvars-. You can > > find it by typing in Stata -findit renvars-. > > > > * > * 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/ -- Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de * * 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/

**Follow-Ups**:**Re: st: Changing part of variable names***From:*Maarten Buis <[email protected]>

**References**:**st: Changing part of variable names***From:*[email protected]

**Re: st: Changing part of variable names***From:*Maarten Buis <[email protected]>

**Re: st: Changing part of variable names***From:*Nick Cox <[email protected]>

- Prev by Date:
**Re: st: Question on ROC analysis** - Next by Date:
**Re: st: Using sampling/probability weights for mixed design ANOVA in STATA** - Previous by thread:
**Re: st: Changing part of variable names** - Next by thread:
**Re: st: Changing part of variable names** - Index(es):