Haluk Vahaboglu
Haluk Vahaboglu

Reputation: 11

duplicated variable labels

I am using Stata 13.1. After importing a data set with more than 50 variables from Excel I realized that there are duplicated variable labels. Stata gave variable names during importing from Excel and changed the duplicated names. However, for some reason I want to find duplicated variable labels and rename these labels as Label1 & Label2 for example.

Could anybody help me to find and list duplicated variable labels?

Upvotes: 1

Views: 449

Answers (2)

user4690969
user4690969

Reputation:

Have you considered, given what you've learned from your initial import, editing the Excel spreadsheet and changing the cells that are creating duplicate variable names to distinct values, and then importing the spreadsheet a second time?

Upvotes: 0

Nick Cox
Nick Cox

Reputation: 37183

Duplicate variable labels are not problematic to Stata, just users.

With no more variables than observations, you could do this in a crude way by copying variable names and labels into data and then looking for duplicates.

gen varlabel = ""
gen varname = "" 
local j = 1
foreach v of var * {
    replace varname = "`v'" in `j'
    replace varlabel = "`: variable label `v''" in `j'
    local ++j
}
duplicates list varname varlabel 

I don't think you're asking for code to rename.

If I had this problem repeatedly (I don't use MS Excel on purpose) I would write a program using Mata.

Upvotes: 1

Related Questions