Dear All,
I am running an analysis about the behavior of some footbal teams in the Italian championship. An example of data is attached:
I need to calculate the difference in the variable "ammoniti" within the same match. Consider the bold cases: THe team Atalanta received 2 yellow cards (ammoniti) when playing against Juventus, which instead received 1 yellow card. What I would like to obtain (wanted) is the difference in the number of yellow cards. In the first case that difference is 1. In the second case, it is -1. It is a bit time consuming to fill in the data "manually". Is there any way I can do it more quickly?
EDIT
I tried the following:
But it does not work.
Any suggestion is highly appreciated.
Thanks,
Dario
I am running an analysis about the behavior of some footbal teams in the Italian championship. An example of data is attached:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte giornate str10(squadra sfid2) byte ammoniti wanted 2 "Atalanta" "Juventus" 2 1 2 "Bologna" "Milan" 1 2 "Brescia" "Lecce" 2 2 "Cagliari" "Fiorentina" 1 2 "Chievo" "Livorno" 3 2 "Fiorentina" "Cagliari" 1 2 "Inter" "Palermo" 3 2 "Juventus" "Atalanta" 1 -1 2 "Lazio" "Reggina" 1 2 "Lecce" "Brescia" 4 2 "Livorno" "Chievo" 3 2 "Messina" "Roma" 5 2 "Milan" "Bologna" 2 2 "Palermo" "Inter" 1 2 "Parma" "Udinese" 3 2 "Reggina" "Lazio" 3 2 "Roma" "Messina" 3 2 "Sampdoria" "Siena" 3 2 "Siena" "Sampdoria" 2 2 "Udinese" "Parma" 2 end
EDIT
I tried the following:
Code:
gen diffy=0 levelsof squadra, local(sq) levelsof sfid2, local(sf) foreach s of local sq{ foreach f of local sf{ replace diffy=ammoniti-ammoniti if "`s'"=="`f'" } }
Any suggestion is highly appreciated.
Thanks,
Dario