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
Related Posts with Reshape long to wide error
Utilizar SPSSHello, I’m trying to use the PISA dataset but I’m not being able convert it from SAS and SPSS. It i…
ComandesHello, I’m trying to use the PISA dataset but I’m not being able convert it from SAS and SPSS. It i…
Stacked bar graph: percentage of total observations, by groupsHello, I would like to produce a graph that shows the percentage of total observations (code_7), ov…
How to get conditional maximum dates and values?Hi all, I would like to find the largest % of institutional ownership for each deal, for example, f…
unbalanced panel data with endogenous explanatory variable and some unobservable variablesHi All, I'm struggling with an equation that has an endogenous regressor (sample selection bias) and…
Subscribe to:
Post Comments (Atom)
0 Response to Reshape long to wide error
Post a Comment