Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: Re: Problem with variable names using Insheet

From   "Joseph Coveney" <>
To   <>
Subject   st: Re: Problem with variable names using Insheet
Date   Mon, 13 May 2013 11:35:33 +0900

Joseph Deckert wrote:

I'm using -insheet- to import data from a .csv file. I have the variable names in the first row of the spreadsheet. When I import the data, the variable names get "aci" put before and after them. So, the variable "votes1" becomes "acivotes1aci" and the variable label becomes "+aci-votes1+aci-"

I've tried including the -tab- and -comma- options after the -insheet- command to no avail. Any suggestions? I feel like I might be missing something obvious.


I'm not sure how to avoid it (I've never seen it happen before), but you can fix it afterward by looping over the variables, renaming them  and replacing the variable labels.  (Stata version 12 has enhanced its -rename- command to do the renaming part more conveniently without looping; type 

    help rename group

in the command window if you have that version and are yet unaware of the new feature.)  You can do both renaming and relabeling with a loop similar to that below.  Note that -rensfix- and -renpfix- are user-written commands.  To install them, type 

    findit rensfix

 in the command window, and go from there.

Beyond that, it might help others on the list help you if you could post the first two lines of you .csv file (or an illustrative portion of the first two lines if there are numerous columns) exactly as contained in the file, and the exact commands that give you this problem.  For the latter, a copy-and-paste from Stata's Results window is often the most illuminating.

Joseph Coveney

foreach var of varlist _all {
    rensfix aci
    renpfix aci
    local variable_label : variable label `var'
    local variable_label : subinstr local variable_label "+aci-" "", all

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index