I have a panel data with 8 waves and 740 000 observations of the id variable. I also created 7 dummy variables of types of contact that take the value of 1 when either political party of those I have in my data contacted an individual with a specific type of contact(sms, in person etc.).
What I want to do is create a bar chart that will sum up the individuals that were contacted by each type of contact and get an absolute value or percentage on the y-axis. However, I don't know how not to count multiple times the same individual as an individual could have been contacted through sms for example in all 8 waves or just in 1. I don't want to count the contact of the same individual 8 times but just once.
What I did up to now is:
Code:
*creating variables of the type of contacts in order to see through a bar chart how the parties used them gen telephone=1 if partyContactSNP_1W==1 | partyContactPC_1W==1 | partyContactLD_1W==1 | partyContactLab_1W==1 | partyContactTIG_1W==1 | partyContactGreen_1W==1 | partyContactBrexit_1W==1 | partyContactUKIP_1W==1 | partyContactCon_1W==1 | partyContactOther_1W==1 gen letter=1 if partyContactSNP_2W==1 | partyContactPC_2W==1 | partyContactLD_2W==1 | partyContactLab_2W==1 | partyContactTIG_2W==1 | partyContactGreen_2W==1 | partyContactBrexit_2W==1 | partyContactUKIP_2W==1 | partyContactCon_2W==1 | partyContactOther_2W==1 gen atHome=1 if partyContactSNP_3W==1 | partyContactPC_3W==1 | partyContactLD_3W==1 | partyContactLab_3W==1 | partyContactTIG_3W==1 | partyContactGreen_3W==1 | partyContactBrexit_3W==1 | partyContactUKIP_3W==1 | partyContactCon_3W==1 | partyContactOther_3W==1 gen inStreet=1 if partyContactSNP_4W==1 | partyContactPC_4W==1 | partyContactLD_4W==1 | partyContactLab_4W==1 | partyContactTIG_4W==1 | partyContactGreen_4W==1 | partyContactBrexit_4W==1 | partyContactUKIP_4W==1 | partyContactCon_4W==1 | partyContactOther_4W==1 gen email=1 if partyContactSNP_5W==1 | partyContactPC_5W==1 | partyContactLD_5W==1 | partyContactLab_5W==1 | partyContactTIG_5W==1 | partyContactGreen_5W==1 | partyContactBrexit_5W==1 | partyContactUKIP_5W==1 | partyContactCon_5W==1 | partyContactOther_5W==1 gen sms=1 if partyContactSNP_6W==1 | partyContactPC_6W==1 | partyContactLD_6W==1 | partyContactLab_6W==1 | partyContactTIG_6W==1 | partyContactGreen_6W==1 | partyContactBrexit_6W==1 | partyContactUKIP_6W==1 | partyContactCon_6W==1 | partyContactOther_6W==1 gen other=1 if partyContactSNP_7W==1 | partyContactPC_7W==1 | partyContactLD_7W==1 | partyContactLab_7W==1 | partyContactTIG_7W==1 | partyContactGreen_7W==1 | partyContactBrexit_7W==1 | partyContactUKIP_7W==1 | partyContactCon_7W==1 | partyContactOther_7W==1 *replacing the missing values with 0 replace telephone=0 if telephone==. replace letter=0 if letter==. replace atHome=0 if atHome==. replace inStreet=0 if inStreet==. replace email=0 if email==. replace sms=0 if sms==. replace other=0 if other==. * egen telephone_bar=max(telephone) if telephone==1 egen letter_bar=max(letter) if letter==1 egen atHome_bar=max(atHome) if atHome==1 egen inStreet_bar=max(inStreet) if inStreet==1 egen email_bar=max(email) if email==1 egen sms_bar=max(sms)if sms==1 egen other_bar=max(other) if other==1
Thanks in advance!
0 Response to multivariable bar chart from panel data
Post a Comment