My little Stata Problem:
I have a table like this:

I want to create a variable that counts the number of different cat for each citing. This is... For the A citing there are 2 cat... the 3 and the 6. So I want another variable (dif_cat) with two 2.
For this sample it would look something like this:

Can you help me?
PS: I know this has nothing to do with Stata (but it may inspire someone) with an actually programming language I would try something such as: Having a cycle doing citing column and checking if equal to the one before Having an auxiliary empty vector Having a second cycle within the first that wouldsee if the current cat was in the vector and if not put it there. When the citing changed I would count the lenght of the auxiliary matrix, reset it and do it again. The problem is that I need this in Stata code :S
I have a table like this:

I want to create a variable that counts the number of different cat for each citing. This is... For the A citing there are 2 cat... the 3 and the 6. So I want another variable (dif_cat) with two 2.
For this sample it would look something like this:

Can you help me?
PS: I know this has nothing to do with Stata (but it may inspire someone) with an actually programming language I would try something such as: Having a cycle doing citing column and checking if equal to the one before Having an auxiliary empty vector Having a second cycle within the first that wouldsee if the current cat was in the vector and if not put it there. When the citing changed I would count the lenght of the auxiliary matrix, reset it and do it again. The problem is that I need this in Stata code :S
Comment