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: --insheet--reading an excel file where row 1,2 are variable names and labels
From
Nick Winter <[email protected]>
To
[email protected]
Subject
Re: st: --insheet--reading an excel file where row 1,2 are variable names and labels
Date
Thu, 23 Sep 2010 11:02:06 -0400
I've done something like this in the past:
foreach var of varlist * {
label variable `var' "`=`var'[2]'"
rename `var' `=`var'[1]'
}
drop in 1/2
destring *, replace
d
list
- nick Winter
On 9/23/2010 10:48 AM, Amanda Fu wrote:
Dear Statalisters,
I got a question when I tried to read an excel file (.csv) into Stata.
In the excel file, the first row and the second row are for the
variable name and labels respectively. But when using --insheet
using---, Stata renamed the variables and the labels are not shown.
Then my question is: is there any easy way to let Stata name the
variables using first row and define labels using the second row when
reading a data set from excel file?
------------------------------------------------------------EXCEL file
name state age a11 a12
name state age interview type household NO.
AJ MA 21 a 001
.........
------------------------------------------------------------
After using --insheet---, the stata data file looks like this:
-------------------------------------------------------------census_variables_copy
var1 var2 var3 var4 var5
name state age a11 a12
name state age interview type household NO.
AJ MA 21 a 001
.........
------------------------------------------------------------
Thanks for your time!
Best wishes,
Amanda
*
* 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/
--
--------------------------------------------------------------
Nicholas Winter 434.924.6994 t
Assistant Professor 434.924.3359 f
Department of Politics [email protected] e
University of Virginia faculty.virginia.edu/nwinter w
S385 Gibson Hall, South Lawn
*
* 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/