Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 72797

how to compute the number of distinct observations

$
0
0
Hi all,

I try to compute the number of distinct observations of a variable: gvkey. I referred to this link: http://www.stata.com/support/faqs/da...t-observations. And I coded as follows.

by execid gvkey, sort: gen ngvkey = _n == 1
by execid gvkey, replace ngvkey =sum(ngvkey)

The first line of codes worked well, but the second line of codes did not work.
Please refer to below example to make a sense what I tried to do.

I tried to see how many times executives move to other firms.

gvkey: an unique id of firms
execid: an unique id of executives

gvkey.execid..year...ngvkey
1234...1000...2000...... 1
1234...1000...2001...... 1
2052...1000...2002...... 2
2052...1000...2003...... 2
2052...1000...2004...... 2
8111...1000...2005...... 3
8111...1000...2006...... 3
4706...2000...1992...... 1
4706...2000...1993...... 1
4706...2000...1994...... 1
7722...2000...1995...... 2
3792...3000...2003.......1

You can see here that executive 1000 moves to other firms 3 times in total and executive 2000 moves to other firms 2 times in total .

I appreciate any comments on this. Thank you!

Regards,
Andy


Viewing all articles
Browse latest Browse all 72797

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>