Search code examples
countstatadistinct-values

Stata Count Distinct Values


In SQL I would do:

SELECT COUNT(DISTINCT column_name,column_name2) AS some_alias FROM table_name

In Stata I would like to do the same ...
I have not found an easy way to do this ...
For example, I import new panel data for 20 Countries - if available, for a timespan over 20 years - a max of 20*20 values.
But some country-year combinations might be missing.
I would like to know then, how many values I have of the possible 400!


Solution

  • ssc inst distinct
    

    will install a function that is very close to what the mentioned SQL statement does. In the case of a dichotomous variable and 20 countries this statement will give the distinct number of value combinations of countries and the dichotomous variable.

    distinct Countries dichVar if dichVar == 1