-2

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!

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
ill
  • 352
  • 2
  • 4
  • 23
  • `search distinct` in Stata points to relevant reviews and commands. In this example, the first check is just that you have 400 observations and that they are distinct using e.g. `isid`. – Nick Cox Oct 12 '15 at 12:03
  • 2
    No attempt at Stata code here, so this is marginal for this forum. – Nick Cox Oct 12 '15 at 12:05
  • jepp sorry, no code provided - poot attempt. lets say i have a dichotome variable (1 or 2). and now i want to know, how many combinations do we have. count if dichotome==1 just gives me the number of observation! – ill Oct 12 '15 at 15:36
  • http://www.stata.com/support/faqs/data-management/number-of-distinct-observations/ ... does not provide a solution, that does't generate a new variable - a couple of 'search distinct' will just genereate new columns everytime - i find that very disturbing – ill Oct 12 '15 at 15:41
  • 2
    I am personally reluctant to start guessing at what your variable names are, etc. Please post **questions** with (a) attempts at code and (b) reproducible examples. The fact that one FAQ doesn't do what you want doesn't constitute a well-posed problem. – Nick Cox Oct 12 '15 at 15:57

1 Answers1

0
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 
Nick Cox
  • 35,529
  • 6
  • 31
  • 47
ill
  • 352
  • 2
  • 4
  • 23
  • Pedantically, or otherwise, `distinct` is a command, **not** a function; and the latest version is downloadable from the _Stata Journal_ website, not SSC. More crucially, the qualifier `if dichVar == 1` will stop the code from doing what you say it does. You need something like `distinct Countries dichVar, joint`. – Nick Cox Oct 12 '15 at 17:59
  • if dichVar == 1 works absolutely fine for me! maybe you are confusing the versions!? the official stata.com website pointed me to ssc ... sorry – ill Oct 13 '15 at 10:56
  • Without your dataset I cannot check but I do not withdraw my comment. As an author of `distinct` I am familiar with how it works (although manifestly not infallible). – Nick Cox Oct 13 '15 at 10:59