I have a dataset about major election in municipalities. For each municipality, each election period, tells me the different candidates and how many votes they get.
Candidates can be elected as major in the first round, or in the second (if they don't reach specific thresholds at the first, they go for the second round).
I would love to create a variable that is named "margin of victory", that tells me the percentage difference from the candidate that gets most votes, relative to the second.
Let's say candidate -A- get 99 votes and candidate -B- 90. Than, margin victory should be equal to 10 (i.e. 10%). Some municipality also have more than 2 candidates.
Ideally this variable has to be calculated at municipality level, each election date, each round.
Given that there might be two rounds, it would be wonderful to have two variables, let's say "margin_round1" and "margin_round2"
I copy and paste a -dataex-
The problem is that I don't have an unique identifiers for each candidate, but name and surname in two different string variables.
Finally, to make sure that municipality can be in 2 different regions with same name, maybe would better to create a unique identifier of each municipality-province-region.
I guess this last problem can be tackled before the calculus of margin of victory as follow:
[CODE]egen id_municipality=group (municipality province region)[/CODE ]
Truly thank you for your help!
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float election_date str35 municipality str30 surname str41 name byte round long votes_candidate 16248 "LATTARICO" "MARI" "MARIO" 1 53 16248 "LATTARICO" "LI PRETI" "GIUSEPPE" 1 1100 16248 "LATTARICO" "IORIO" "GIANLUCA" 1 497 16248 "LATTARICO" "BARCI" "ANTONIO GIANFRANCO" 1 1274 16248 "PARENTI" "RIGA" "ANTONIO " 1 852 16248 "PARENTI" "MARSIGLIA" "GIOVANNI" 1 841 16248 "PATERNO CALABRO" "IANNITELLI" "SALVATORE" 1 467 16248 "PATERNO CALABRO" "ESPOSITO " "ACHILLE FRANCESCO" 1 519 16248 "PIANE CRATI" "FILICE" "EUGENIO" 1 378 16248 "PIANE CRATI" "AMBROGGIO" "MICHELE" 1 687 16248 "SANTO STEFANO DI ROGLIANO" "ORRICO" "ANTONIO" 1 577 16248 "SANTO STEFANO DI ROGLIANO" "CONSOLO" "SALVATORE" 1 483 16248 "FAGNANO OLONA" "LOFANO" "ANNALISA" 1 575 16248 "FAGNANO OLONA" "ROSSI" "SANTINO" 1 2585 16248 "FAGNANO OLONA" "NAVARRA" " GIACOMO" 1 2278 16248 "FAGNANO OLONA" "MORETTI" "DARIO" 1 372 16248 "APRIGLIANO" "ROMANO" "SILVIA" 1 602 16248 "APRIGLIANO" "MELE" "SALVATORE" 1 507 16248 "APRIGLIANO" "GALLUCCI " "FRANCESCO" 1 912 16248 "BIANCHI" "ELIA" "LUIGI" 1 387 16248 "BIANCHI" "VILLELLA" "FRANCESCO" 1 552 16248 "BIANCHI" "MIGLIAZZO" "FRANCO" 1 132 16248 "FIUMEFREDDO BRUZIO" "ALOISE" "VINCENZO" 1 1450 16248 "FIUMEFREDDO BRUZIO" "MALITO" "ANGELO" 1 912 16529 "BASSIGNANA" "PELIZZARI" "ROSALBA" 1 712 16529 "BASSIGNANA" "CERVARI" "ANGELO" 1 480 16529 "CARREGA LIGURE" "CHIESA" "UMBERTO CARLO" 1 20 16529 "CARREGA LIGURE" "TRAVERSO" "ANNA MARINA" 1 24 16529 "CARREGA LIGURE" "GOZZANO" "GUIDO" 1 41 16529 "CASSINE" "GOTTA" "ROBERTO" 1 943 16529 "CASSINE" "BALDI" "GIANFRANCO LORENZO" 1 512 16529 "CASSINE" "PRETTA" "CLAUDIO" 1 543 16529 "GAMALERO" "TROCCA" "GIORGIO" 1 140 16529 "GAMALERO" "TAVERNA" "NADIA" 1 242 16529 "GAMALERO" "PRIGIONE" "ANNA MARIA MARGHERITA" 1 200 16529 "MONTACUTO" "SALA" "MAURO ANGELO AGOSTINO" 1 67 16529 "MONTACUTO" "FERRARI" "GIOVANNI CARLO PIETRO" 1 207 16529 "VALENZA" "RASELLI" "GIANNI" 1 6790 16529 "VALENZA" "BERTONCELLI" "ROBERTO" 1 101 16529 "VALENZA" "BELLINI" "LIVIANO" 1 144 16529 "VALENZA" "NATALE" "ALBERTO" 1 148 16529 "VALENZA" "ROSSI" "LUCA ANGELO" 1 4804 16529 "VALENZA" "BARIGGI" "LUCA FERDINANDO" 1 421 16529 "SENIGALLIA" "SAVINI" "VINCENZO" 1 5885 16529 "SENIGALLIA" "ANGELONI" "LUANA" 1 14999 16529 "SENIGALLIA" "MASSACESI" "LUCIO" 1 2427 16529 "SENIGALLIA" "MARCANTONI" "FABRIZIO" 1 3341 16529 "APPIGNANO DEL TRONTO" "VANNICOLA" "PIETRO" 1 687 16529 "APPIGNANO DEL TRONTO" "AGOSTINI" "MARIA NAZZARENA" 1 746 16529 "BAIANO" "CAVACCINI" "VINCENZO" 1 1689 16529 "BAIANO" "NAPOLITANO" "CARMINE FORTUNATO" 1 1620 16529 "CASTELFRANCI" "TECCE" "EUGENIO" 1 975 16529 "CASTELFRANCI" "BOCCHINO" "ANGELO" 1 616 16529 "CERVINARA" "CIOFFI" "DOMENICO" 1 1724 16529 "CERVINARA" "CIOFFI" "FRANCO" 1 2716 16529 "CERVINARA" "CLEMENTE" "SERGIO" 1 2413 16529 "MERCOGLIANO" "SACCARDO" "TOMMASO" 1 4000 16529 "MERCOGLIANO" "VALENTE" "MODESTINO" 1 3868 16529 "MONTELLA" "MARANO" "GABRIELE" 1 383 16529 "MONTELLA" "VESTUTO" "SALVATORE" 1 2584 16529 "MONTELLA" "CAPONE" "FERRUCCIO" 1 2208 16529 "MOSCHIANO" "DALIA" "LUCIANO ELIGIO" 1 519 16529 "MOSCHIANO" "ADDEO" "LELIO" 1 667 16529 "QUINDICI" "SANTANIELLO" "LIBERATO" 1 872 16529 "QUINDICI" "PAGLIARO" "MARIO" 1 21 16529 "QUINDICI" "SANTANIELLO" "FILIPPO" 1 581 16529 "SORBO SERPICO" "TEDESCO" "ROCCO" 1 294 16529 "SORBO SERPICO" "GALANTE" "PATRIZIA" 1 98 16529 "ALTAMURA" "STACCA" "MARIO ANTONIO FELICE" 1 22259 16529 "ALTAMURA" "GIANCASPRO" "VINCENZO" 1 1023 16529 "ALTAMURA" "PETRONELLA" "FRANCESCO" 1 2045 16529 "ALTAMURA" "COLONNA" "VINCENZO DETTO ENZO" 1 3509 16529 "ALTAMURA" "GENCO" "GIUSEPPE" 1 11158 16529 "CAPURSO" "DI GIOIA" "PASQUALE" 1 2312 16529 "CAPURSO" "SELVAGGIO" "VINCENZO" 1 1008 16529 "CAPURSO" "DE NATALE" "GIUSEPPE" 1 3555 16529 "CAPURSO" "MONACO" "GIUSEPPE DETTO PINO" 1 123 16529 "CAPURSO" "CARELLA" "GIOACCHINO" 1 1731 16529 "GRAVINA IN PUGLIA" "CORNACCHIA" "NICOLA DETTO COCCO" 1 1076 16529 "GRAVINA IN PUGLIA" "VENDOLA" "ONOFRIO DETTO RINO" 1 14781 16529 "GRAVINA IN PUGLIA" "MASIELLO" "ANTONIO" 1 10209 16529 "GRAVINA IN PUGLIA" "CONTICCHIO" "MICHELE" 1 1231 16529 "GRUMO APPULA" "PANZARINO" "VITO" 1 4372 16529 "MOLA DI BARI" "BERLEN" "NICOLA" 1 8086 16529 "MOLA DI BARI" "BERLEN" "NICOLA" 2 8282 16529 "MOLA DI BARI" "TANZI" "NICOLA" 2 6919 16529 "MOLA DI BARI" "TANZI" "NICOLA" 1 7384 16529 "MOLA DI BARI" "REDAVID" "ISABELLA" 1 227 16529 "MOLA DI BARI" "LATERZA" "ANDREA GIORGIO" 1 703 16529 "BORCA DI CADORE" "CAPRONI" "MASSIMO" 1 202 16529 "BORCA DI CADORE" "DE LUCA" "MASSIMO CIAN" 1 306 16529 "RONCADELLE" "BORGHETTI" "VITTORIO" 1 423 16529 "RONCADELLE" "ORLANDO" "MICHELE" 1 3606 16529 "RONCADELLE" "MAFFEI" "LUCA" 1 1343 16529 "CEGLIE MESSAPICA" "FEDERICO" "PIETRO" 2 7696 16529 "CEGLIE MESSAPICA" "FEDERICO" "PIETRO" 1 6136 16529 "CEGLIE MESSAPICA" "MAGNO" "PIETRO" 1 2944 16529 "CEGLIE MESSAPICA" "CIRACI'" "NICOLA" 1 3704 16529 "CEGLIE MESSAPICA" "CIRACI'" "NICOLA" 2 3941 16529 "CEGLIE MESSAPICA" "NIGRO" "FRANCO" 1 657 end format %td election_date
0 Response to Creating margin victory election data
Post a Comment