-1

To say that a dataset is (person, year) level means that each row of that dataset has different (person, year) like this:

person  year  wage
  Mike   2000   10
  Mike   2010   30
  Jack   1990   20

How can I make Stata display exactly those (person, year) variable sets that uniquely define each row?

I want to make a log file to record

person year

only, but not display any individual information (displaying individuals' information in a log file is against the rules set by the data provider).

How could I do this?

What I thought about is using bysort in some way

bysort person year: gen num=_n

and if every num is 1, then it means (person, year) defines each row.

But if a dataset is extremely large, then checking whether every num is 1 is too tedious. Is there any smarter way?

2
  • Lack of research is evident. Just skimming through the [D] Data management manual would identify relevant commands. Also, Stata has many FAQs on its website.
    – Nick Cox
    Dec 19, 2018 at 10:26
  • In Stata rows are called observations. I guess you would not ask an Excel question using the term observations, and the converse follows
    – Nick Cox
    Dec 19, 2018 at 10:26

1 Answer 1

1

The command isid checks whether the variables you supply do jointly specify observations uniquely. Here is an example you can try:

. webuse grunfeld, clear

. isid company
variable company does not uniquely identify the observations
r(459);

. isid company year

Note the principle: no news is good news.

Another way to check for problems is through duplicates. For example, try duplicates list person year. In your case, you don't want that in the log. But what you can do first is anonymise your persons through

egen id = group(person) 

and then check for duplicates on id year.

See also this FAQ.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.