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, is already up and running.

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

st: extract labels from first row of data

From   Will Hauser <>
To   <>
Subject   st: extract labels from first row of data
Date   Tue, 20 Sep 2011 11:46:19 -0400

I'm attempting to import census data using the insheet command and the data
is organized such that the variable names are on the first row and the
labels are on the second.  Using the 'names' option gets me a dataset with
correct variable names and the labels are in the first observation.

After searching the archives I believe I have to extract the labels using a
foreach loop and then destring the variables but I can't seem to structure
the loop correctly.  I'm also wondering if there's a user written program to
do this.  It seems a little bizarre to me that a program as amazingly
versatile as Stata would require a workaround to import something as
universally used as US Census data.

Here's what I've tried so far using Stata 12:
insheet using "C:\Users\Will\CensusData.txt", delimiter("|") names clear

(GEO is the first variable in the dataset and PO13002 is the last)

foreach var of varlist (GEO_ID-P013002) {
	label variable `var' "`var'" if (_n==1)

I know I need to reference the content of the variable in obs 1 and I'm not
sure how to do that.  


Will Hauser

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index