I'm trying to import excel data (.xlsx) using code that works for other excel workbooks, but for some reason it is not working here. I use the first row as variable names and the second row as variable labels, with the data following.
It works until the rename statement, when I get a "syntax error" r(198). However, when I use this exact code, just with a different xlsx file, it runs perfectly. Any thoughts on what I'm missing here?
Code:
import excel using mydata.xlsx , clear cellrange(A1:AJ365)
foreach var of varlist * {
local row1 = `var'[1]
local row2 = `var'[2]
label var `var' "`row2'"
local vn = strtoname("`row1'")
rename `var' `vn'
}

Comment