Bookmark and Share

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]

Re: st: Importing data with improper variable names


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: Importing data with improper variable names
Date   Tue, 3 Aug 2010 16:36:50 +0000

<>

You can avoid the pre-proscessing by using the "nonames" option with insheet and then use -autorename- (from SSC) to rename the vars with the years.  This will be flexible with files that contain different years.   This example uses some fake data I put in my dropbox:

**********!
clear
cap which autorename
if _rc ssc install autorename, replace

insheet using "http://dl.dropbox.com/u/428249/test.csv";, nonames comma
autorename   //this will add a underscore the front of the year to make it a varname
save using.dta, replace

clear
insheet using "http://dl.dropbox.com/u/428249/test2.csv";, nonames comma
autorename
save master.dta, replace

append using using.dta
save master.dta, replace
li
**********!

~ Eric

On Aug 3, 2010, at 11:07 AM, Glenn Hoetker wrote:

> Greetings all.
> 
> I have data downloaded as a text file from a website that comes in a form like
> 
> 	"Name",	"2001",	"2002",	"2003"
> 	"Fred", "3", "3", "0" 
> 
> It's just a text file, so I'd normally just use
> 
> 	insheet using data.text, names
> 
> However, since variable names can't begin with a number, the last variables get renamed v3 v4 v5.  That's inconvenient, because it's meant to be a year.   I can manually rename v3 to year2001, etc., but would rather not do so--I'll be importing this data fairly often,  v3 may not always map to 2001, and there are actually many more years than I've shown here.
> 
> Can anyone suggest a way around this problem?  I'm using Stata 11 and have access to StatTransfer.  I'm on a Mac, giving me access to both AppleScript and the standard Unix suite of tools to pre-process the file, but I'm rusty with those and would prefer a "pure Stata" solution if feasible.  
> 
> Thank you for any pointers.
> 
> Glenn
> 
> Glenn Hoetker
> Julian Simon Faculty Fellow in Business
> Associate Professor (Law, Institute for Genomic Biology)
> Director, Center for International Business Education and Research
> Faculty Fellow, Academy for Entrepreneurial Leadership
> University of Illinois
> 217-265-4081
> [email protected]
> http://www.business.uiuc.edu/ghoetker
> 
> 
> *
> *   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index