Hello everyone,
I have retrieved databases in Excel of election results. Unfortunately in the Excel databases the name of the variables is common to all candidates. When I import the databases into Stata, the first occurrence of the variables works but then Stata obviously renames the variables already used by letters, so I get this (reduced database for the example):
I would like to rename the necessary variables to Name Surname Votes Vote_Registred and then add 1 to the end of each variable name for candidate 1, 2 to the end of each variable name for candidate 2, and so on. We would get this:
Are there any commands to do this? I can't get away with using the rename command to make Stata understand that it should add an increment of one to the names of each variable for each new candidate
Thank you in advance,
Regards
I have retrieved databases in Excel of election results. Unfortunately in the Excel databases the name of the variables is common to all candidates. When I import the databases into Stata, the first occurrence of the variables works but then Stata obviously renames the variables already used by letters, so I get this (reduced database for the example):
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str9 CityName byte(Total_Registered Total_Voting) str5 Name str8 Surname byte Votes double Vote_Registered str5 M str8 N byte O double P str5 R str8 S byte T double U "CityName1" 30 28 "Name1" "Surname1" 10 33.33333333333333 "Name2" "Surname2" 15 50 "Name3" "Surname3" 3 10 "CityName2" 25 19 "Name1" "Surname1" 9 36 "Name2" "Surname2" 5 20 "Name3" "Surname3" 5 20 "CityName3" 48 33 "Name1" "Surname1" 21 43.75 "Name2" "Surname2" 8 16.666666666666664 "Name3" "Surname3" 4 8.333333333333332 end
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str9 CityName byte(Total_Registered Total_Voting) str5 Name1 str8 Surname1 byte Votes1 double Vote_Registered1 str5 Name2 str8 Surname2 byte Votes2 double Vote_Registered2 str5 Name3 str8 Surname3 byte Votes3 double Vote_Registered3 "CityName1" 30 28 "Name1" "Surname1" 10 33.33333333333333 "Name2" "Surname2" 15 50 "Name3" "Surname3" 3 10 "CityName2" 25 19 "Name1" "Surname1" 9 36 "Name2" "Surname2" 5 20 "Name3" "Surname3" 5 20 "CityName3" 48 33 "Name1" "Surname1" 21 43.75 "Name2" "Surname2" 8 16.666666666666664 "Name3" "Surname3" 4 8.333333333333332 end
Thank you in advance,
Regards
Comment