I am using the user-written egen_inequal package which calculates inequality statistics such as the Gini. I am calculating the Gini for by-groups. If the by-groups are defined using a numeric variable, I can get the Gini. But if the by-groups are defined using a string variable, all I get are missing values.
Some questions:
1. Is it common for the by() option only to work with numeric variables?
2. If my groups are defined by a string variable, what can I do to get the results I want?
Here is some example code.
--------------------------------------
ssc install egen_inequal
sysuse auto, clear
/* foreign is a numeric variable.
Let's create a string variable Foreign representing the same information. */
gen Foreign="Foreign" if foreign==1
replace Foreign="Domestic" if foreign==0
egen gini=gini(price), by(foreign)
/* This works fine, because foreign is numeric. */
drop gini
egen gini=gini(price), by (Foreign)
/* This generates missing values, because Foreign is a string. */
Some questions:
1. Is it common for the by() option only to work with numeric variables?
2. If my groups are defined by a string variable, what can I do to get the results I want?
Here is some example code.
--------------------------------------
ssc install egen_inequal
sysuse auto, clear
/* foreign is a numeric variable.
Let's create a string variable Foreign representing the same information. */
gen Foreign="Foreign" if foreign==1
replace Foreign="Domestic" if foreign==0
egen gini=gini(price), by(foreign)
/* This works fine, because foreign is numeric. */
drop gini
egen gini=gini(price), by (Foreign)
/* This generates missing values, because Foreign is a string. */
Comment