Hello stateliest, Im having trouble trying to reshape my data set from long-wide. My code can be found below but if I was to try to do a final reshape wide it says that im having an error with my i () and j () variable because they must identify uniquely in the observation.

cd /Users/Desktop/county/

clear
save FL_2012.dta, replace emptyok

foreach county in ALA BAK BAY BRA BRE_1 BRE_2 BRE_3 BRO CAL CHA ///
CIT CLA CLL CLM DAD DES DIX DUV ESC FLA FRA GAD ///
GIL GLA GUL HAM HAR HEN HER HIG HIL HOL IND JAC ///
JEF LAF LAK LEE LEO LIB MAD MAN MON MRT NAS OKA ///
OKE OSC PAL PAS PIN PUT SAN SAR SEM STJ STL ///
SUM_2 SUM_1 SUW TAY UNI VOL WAK WAL WAS {

import delimited using "`county'.txt", clear

append using FL_2012.dta,

save FL_2012.dta, replace

}


rename v2 county
rename v7 precinct
rename v8 precinct_id
rename v12 race
rename v13 district
rename v14 race_code
rename v15 candidate
rename v16 partyid
rename v17 reg_num
rename v18 reten_num
rename v19 vote_total

drop v1 v3 v4 v5 v6 v9 v10 v11

*keeping party observations; dropping unaffiliated*


keep if partyid == "REP"| partyid == "DEM" | partyid == "LBT" ///

keep if race == "President of the United States" | race == "State Representative" |race == "State Senator" | race == "United States Senator" | race == "U.S. Representative"

*---------------------------------------------------------------------------

gen precinctid = partyid + "_" + precinct
encode precinctid, gen (precinctnum)

encode partyid, gen (partynum)
gen precinct_party = precinctnum + partynum

*gen ID = precinct_id*100 + partynum

egen ID = concat (precinct_id partynum)

encode race, gen (racenum)

egen total_votes = total (vote_total), by(candidate race)

sort total_votes

duplicates tag ID racenum, gen (tag)

duplicates drop


//---------------------------------------------------------------------//


*THIS IS WHERE MY ERROR OCCURS*


reshape wide candidate race, i(precinct_party) j(racenum)



//---------------------------------------------------------------------//

capture tostring precinct, replace

append using FL_2012.dta

save FL_2012.dta, replace