Hi all,
I am relatively new to using Stata and I am struggling with reshaping some data.
I have a .csv file which comprises of election results. The data is not properly arranged in columns and therefore looks odd (data sample below). I wish to make District, Block, Seat Name, Total Elector, Votes Polled, Votes Rejected, OSN, Candidate Name, Party Name and Vote Secured into variables. Currently they are observations. I have multiple .csv sheets like this and I wish to repeat the same steps for the others preferably using a loop.
Thanks!
Noyonika
[CODE]
* Example generated by -dataex-. For more info, type help dataex
clear
input str51 v1 str13 v2 str12 v3 str14 v4 str3 v5 str21 v6 str10 v7 str12 v8
"Panchayat General Election 2013 — Detailed Result" "" "" "" "" "" "" ""
"District : Burdwan" "" "" "" "" "" "" ""
"Block : BHATAR" "" "" "" "" "" "" ""
"" "" "" "" "" "" "" ""
"Polling Date : 15-07-2013" "" "" "" "" "" "" ""
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"MAHATA /PS-1" "5668" "4896" "218" "1" "TUMPA NASKAR" "CPIM" "1871"
"SCW" "" "" "" "" "" "" ""
"" "" "" "" "2" "SUSHANTI MISTRI" "AITC" "2807"
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"MAHATA /PS-2" "4877" "4213" "99" "1" "DILIP SOREN" "AITC" "2463"
"ST" "" "" "" "" "" "" ""
"" "" "" "" "2" "SUNIL MURMU" "CPIM" "1651"
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"MAHATA /PS-3" "5585" "" "" "1" "BIBI MURMU" "AITC" ""
"STW" "" "" "" "" "" "" ""
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"ERUAR /PS-4" "5078" "" "" "1" "BHAGIRATHI HALDER" "AITC" ""
"W" "" "" "" "" "" "" ""
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"ERUAR /PS-5" "4826" "" "" "1" "ABIR DAS" "AITC" ""
"SC" "" "" "" "" "" "" ""
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"ERUAR /PS-6" "5342" "" "" "1" "RUPALI SAHA" "AITC" ""
"W" "" "" "" "" "" "" ""
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"NITYANANDAPUR /PS-7" "5247" "4228" "68" "1" "ANITA SANTRA" "BJP" "126"
"SCW" "" "" "" "" "" "" ""
"" "" "" "" "2" "APARNA SAHA" "AITC" "2421"
"" "" "" "" "3" "SUMITRA KUSHMETE" "CPIM" "1613"
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"NITYANANDAPUR /PS-8" "5387" "4286" "125" "1" "GITA RANI KARFA" "CPIM" "1496"
"W" "" "" "" "" "" "" ""
"" "" "" "" "2" "PIU SAMANTA" "AITC" "2665"
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"NITYANANDAPUR /PS-9" "5404" "4600" "191" "1" "GOUTAM SAMANTA" "BJP" "122"
"General" "" "" "" "" "" "" ""
"" "" "" "" "2" "JAMAL HOSSAIN SEKH" "CPIM" "1772"
"" "" "" "" "3" "MOYNUL HAQUE" "AIUDF" "291"
"" "" "" "" "4" "SAMIR HAZRA" "IND" "18"
"" "" "" "" "5" "SK NURALAM" "AITC" "2206"
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"BOLGONA /PS-10" "5040" "4146" "203" "1" "TAPAS MAJI" "IND" "463"
"SC" "" "" "" "" "" "" ""
"" "" "" "" "2" "DILIP KUMAR MALIK" "AIFB" "1443"
"" "" "" "" "3" "MANOJ KUMAR MA
I am relatively new to using Stata and I am struggling with reshaping some data.
I have a .csv file which comprises of election results. The data is not properly arranged in columns and therefore looks odd (data sample below). I wish to make District, Block, Seat Name, Total Elector, Votes Polled, Votes Rejected, OSN, Candidate Name, Party Name and Vote Secured into variables. Currently they are observations. I have multiple .csv sheets like this and I wish to repeat the same steps for the others preferably using a loop.
Thanks!
Noyonika
[CODE]
* Example generated by -dataex-. For more info, type help dataex
clear
input str51 v1 str13 v2 str12 v3 str14 v4 str3 v5 str21 v6 str10 v7 str12 v8
"Panchayat General Election 2013 — Detailed Result" "" "" "" "" "" "" ""
"District : Burdwan" "" "" "" "" "" "" ""
"Block : BHATAR" "" "" "" "" "" "" ""
"" "" "" "" "" "" "" ""
"Polling Date : 15-07-2013" "" "" "" "" "" "" ""
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"MAHATA /PS-1" "5668" "4896" "218" "1" "TUMPA NASKAR" "CPIM" "1871"
"SCW" "" "" "" "" "" "" ""
"" "" "" "" "2" "SUSHANTI MISTRI" "AITC" "2807"
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"MAHATA /PS-2" "4877" "4213" "99" "1" "DILIP SOREN" "AITC" "2463"
"ST" "" "" "" "" "" "" ""
"" "" "" "" "2" "SUNIL MURMU" "CPIM" "1651"
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"MAHATA /PS-3" "5585" "" "" "1" "BIBI MURMU" "AITC" ""
"STW" "" "" "" "" "" "" ""
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"ERUAR /PS-4" "5078" "" "" "1" "BHAGIRATHI HALDER" "AITC" ""
"W" "" "" "" "" "" "" ""
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"ERUAR /PS-5" "4826" "" "" "1" "ABIR DAS" "AITC" ""
"SC" "" "" "" "" "" "" ""
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"ERUAR /PS-6" "5342" "" "" "1" "RUPALI SAHA" "AITC" ""
"W" "" "" "" "" "" "" ""
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"NITYANANDAPUR /PS-7" "5247" "4228" "68" "1" "ANITA SANTRA" "BJP" "126"
"SCW" "" "" "" "" "" "" ""
"" "" "" "" "2" "APARNA SAHA" "AITC" "2421"
"" "" "" "" "3" "SUMITRA KUSHMETE" "CPIM" "1613"
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"NITYANANDAPUR /PS-8" "5387" "4286" "125" "1" "GITA RANI KARFA" "CPIM" "1496"
"W" "" "" "" "" "" "" ""
"" "" "" "" "2" "PIU SAMANTA" "AITC" "2665"
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"NITYANANDAPUR /PS-9" "5404" "4600" "191" "1" "GOUTAM SAMANTA" "BJP" "122"
"General" "" "" "" "" "" "" ""
"" "" "" "" "2" "JAMAL HOSSAIN SEKH" "CPIM" "1772"
"" "" "" "" "3" "MOYNUL HAQUE" "AIUDF" "291"
"" "" "" "" "4" "SAMIR HAZRA" "IND" "18"
"" "" "" "" "5" "SK NURALAM" "AITC" "2206"
"Seat Name" "Total Elector" "Votes Polled" "Votes Rejected" "OSN" "Candidate Name" "Party Name" "Vote Secured"
"BOLGONA /PS-10" "5040" "4146" "203" "1" "TAPAS MAJI" "IND" "463"
"SC" "" "" "" "" "" "" ""
"" "" "" "" "2" "DILIP KUMAR MALIK" "AIFB" "1443"
"" "" "" "" "3" "MANOJ KUMAR MA

Comment