Apologies in advance if my problem is unclear. I'm a former Stata user who has since been using Excel and previously SAS so I'm trying to remember what I used to know in Stata. I'm trying to count the number of times a distinct combination appears for two string variables. What I would like to see is something like this where the total number of times a country appears across the combination of country and area:
Country | Number of Actions |
Afghanistan | 2 |
Albania | 1 |
Algeria | 2 |
Angola | 2 |
Armenia | 3 |
Azerbaijan | 1 |
Bangladesh | 2 |
Belize | 2 |
Benin | 5 |
Bhutan | 4 |
Bolivia | 6 |
Bosnia and Herzegovina | 1 |
This is what my data looks like:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str47 country str19 area "Afghanistan" "Social Programs" "Afghanistan" "Social Programs" "Albania" "Enforcement" "Algeria" "Enforcement" "Algeria" "Legal Framework" "Angola" "Enforcement" "Angola" "Social Programs" "Armenia" "Coordination" "Armenia" "Social Programs" "Armenia" "Social Programs" "Azerbaijan" "Social Programs" "Bangladesh" "Enforcement" "Bangladesh" "Legal Framework" "Belize" "Enforcement" "Belize" "Legal Framework" "Benin" "Enforcement" "Benin" "Enforcement" "Benin" "Government Policies" "Benin" "Social Programs" "Benin" "Social Programs" end
unknown egen function rowvals()
r(133);
Any help would be appreciated and please let me know if I can clarify!
Thanks!
0 Response to Create a variable that summarizes the number of distinct combinations of string variables
Post a Comment