Dear all,
I was a long time user a long time ago and am a returnee, and I need your help.
There is election data with: a time variable t, a location variable subunit, a count variable p for P candidate, and the other count variable q for Q candidate. My goal is to analyze p and q overtime and each subunit. The data look like this:
t subunit p q p_q total_p_q
0001 a 0 0 0 0
0001 a 1 0 1 0
.
.
.
2359 a 122 120 2 0
2400 a 122 122 0 0
0001 b 0 0 0 30
0001 b 0 1 1 30
.
.
.
2359 b 70 100 30 30
2400 b 70 100 30 30
0001 c 1 0 10
0001 c 1 3 10
.
.
.
2359 c 180 191 11 10
2400 c 190 200 10 10
Later I generated a p_q for p minus q. And then I did the following for the final count for each candidate at each subunit.
bysort subunit: egen p_final=max(park)
bysort subunit: egen q_final=max(moon)
bysort subunit: egen total_final=max(total)
They worked because the maximum equals the latest figure--the values at 2400.
But the problem is this:
bysort subunit: egen p_m_final=max(p_q)
This doesn't because the final count can be a negative number (q wins the p in the subunit) and is not the same as the maximum value.
How can I reach the final value and fill it up for the subunit? In other words, how can I get 0 for subunit A, 30 for B, 10 for C and generate p_q_total as shown in the example?
I was a long time user a long time ago and am a returnee, and I need your help.
There is election data with: a time variable t, a location variable subunit, a count variable p for P candidate, and the other count variable q for Q candidate. My goal is to analyze p and q overtime and each subunit. The data look like this:
t subunit p q p_q total_p_q
0001 a 0 0 0 0
0001 a 1 0 1 0
.
.
.
2359 a 122 120 2 0
2400 a 122 122 0 0
0001 b 0 0 0 30
0001 b 0 1 1 30
.
.
.
2359 b 70 100 30 30
2400 b 70 100 30 30
0001 c 1 0 10
0001 c 1 3 10
.
.
.
2359 c 180 191 11 10
2400 c 190 200 10 10
Later I generated a p_q for p minus q. And then I did the following for the final count for each candidate at each subunit.
bysort subunit: egen p_final=max(park)
bysort subunit: egen q_final=max(moon)
bysort subunit: egen total_final=max(total)
They worked because the maximum equals the latest figure--the values at 2400.
But the problem is this:
bysort subunit: egen p_m_final=max(p_q)
This doesn't because the final count can be a negative number (q wins the p in the subunit) and is not the same as the maximum value.
How can I reach the final value and fill it up for the subunit? In other words, how can I get 0 for subunit A, 30 for B, 10 for C and generate p_q_total as shown in the example?