1
votes

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?

2

2 Answers

1
votes

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.

0
votes

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?