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

From |
Richard Goldstein <richgold@ix.netcom.com> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Wed, 26 Mar 2008 15:03:15 -0400 |

first, note that your two-year comparison works for greater than 2 years also; i.e., the first comparison will be year1 v year2 while the second will be that same year2 v year3 -- thus, the additional command is unnecessary;

the additional command does not work, I think because I don't believe one is allowed to do if a==b==c; however, why Stata does not give an error message; it did give me an error message!

Rich

minimus wrote:

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/

* * 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/

**References**:**st: counting the cases for which the obervations of two different variables are equal***From:*minimus <t24680@hotmail.com>

- Prev by Date:
**st: counting the cases for which the obervations of two different variables are equal** - Next by Date:
**Re: st: MAC Questions** - Previous by thread:
**st: counting the cases for which the obervations of two different variables are equal** - Next by thread:
**st: RE: counting the cases for which the obervations of two different variables are equal** - Index(es):

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