Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Renaming variables, bis


From   Eric Booth <ebooth@ppri.tamu.edu>
To   "<statalist@hsphsun2.harvard.edu>" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Renaming variables, bis
Date   Tue, 12 Apr 2011 21:29:13 +0000

<>

Try -autorename- from SSC.  So, you could do this:

*******************!
clear

input str10(v1 v2 v3 v4)
"1" "2" "3" "4"
"1" "2" "3" "4"
"1" "2" "3" "4"
"1" "2" "3" "4"
"1" "2" "3" "4"
"1" "2" "3" "4"
"1" "2" "3" "4"
"1" "2" "3" "4"
"my real varname" "var2" "var 3" "v44"
"1" "2" "3" "4"
"1" "2" "3" "4"
"1" "2" "3" "4"
"1" "2" "3" "4"
end

li
drop in 1/8
autorename, vsep("_") 
li
*********************!

- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu



On Apr 12, 2011, at 5:35 AM, BAIJER Jan 212040 wrote:

> Hello Stata,
> 
> I have a tab delimited text file that I would like to work on using Stata. This file has a header that I'd like to eliminate; line 9 of the file contains variable names, lines 10 and further contain the observations.
> 
> I'd like to "transform" my datafile from within Stata, by dropping the first 8 lines, and renaming the variables correctly. There must be a smart way of doing this ?! I could not find out how to get rid of the generic variable names, and instruct Stata to use the information on a given (first) line of the file for variable names.
> 
> It so appears (...) that the intended variable names (first observation of each variable) have spaces inthem, so I would probably be looking to try to eliminate those by "subinstr", but I can't get that to work.
> 
> I have tried several variants of :
> 
> foreach var of varlist _all {
> 
>    local NewVarName = subinstr ("`var'[1]'"," ","_")
> 
>    ren `var' `NewVarName'
> 
> }
> 
> Thank you for helping out on this !
> 
> 
> Jan
> 
> ------------------------------------
> Jan Baijer, Ph.D.
> Director of Flow Cytometry
> CEA-DSV-iRCM
> jan.baijer@cea.fr
> 
> 
> 
> *
> *   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/




*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index