Hi,
I want to save a dataset containing the frequencies of various variables for all possible value labels, including those that are not included in the original dataset (see below the current and desired output). Any suggestions?
Thanks!
I want to save a dataset containing the frequencies of various variables for all possible value labels, including those that are not included in the original dataset (see below the current and desired output). Any suggestions?
Thanks!
Code:
clear all
input id country
1 1
2 1
3 1
4 2
5 3
6 4
7 2
8 4
9 2
10 3
end
forvalues i=1/5 {
la def country `i' "Country `i'", modify
}
la val country country
labelbook country
gen one=1
collapse (sum) one, by(country)
list
/*
+-----------------+
| country one |
|-----------------|
1. | Country 1 3 |
2. | Country 2 3 |
3. | Country 3 2 |
4. | Country 4 2 |
+-----------------+
Ideal output:
+-----------------+
| country one |
|-----------------|
1. | Country 1 3 |
2. | Country 2 3 |
3. | Country 3 2 |
4. | Country 4 2 |
5. | Country 5 0 |
+-----------------+
*/

Comment