Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: counting the cases for which the obervations of two different variables are equal


From   minimus <[email protected]>
To   [email protected]
Subject   st: counting the cases for which the obervations of two different variables are equal
Date   Wed, 26 Mar 2008 19:52:48 +0100

Dear All,

I have a question.

I would like to count the number of cases for which the observations inside 
two different variables are equal.
That is: Suppose you have a panel dataset where the variable 'respondent 
number' repeats itself for some years (because the same person is observed 
for several years) and therefore the variable 'sex'  repeats itself too.

So if in the column of respndent number it reads for two obervations:

1011
1011

then the corresponding column the sex reads

male
male
.

Ok now I would like to check if the 'sex' variable is consistent in the 
data. To do this i use the following command:

count if respnr[_n] == respnr[_n+1] & aa001[_n] == aa001[_n+1]



and it returns me a number, which is fine.



This command returns me the number of cases where a respondent is observed 
for any two years and the sex of the respondent was same for those two 
years.



Now, I also ask the same question for '3 consecutive' years and use the 
following command:


count if respnr[_n] == respnr[_n+1] == respnr[_n+2] & aa001[_n] == 
aa001[_n+1] == aa001[_n+2]


Although I can see in the data browser that this condition holds for many 
observations, stata returns "0" cases.
That is, although I determine cases where an individual is observed for 
three years and his sex is male for those years,
stat does not see that and return "0".

Why?









*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index