Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: Programming advice


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Re: Programming advice
Date   Fri, 28 Mar 2003 14:36:59 -0000

Martyn Sherriff

< first line(s) not transmitted>
> are binary responses to a question. The records are paired with the
nth
> record being the parent's response and the n+1 the Childs. The
question is
> simple, how often do the parents and children have the same
response? I have
> used a crude approach by splitting the data into a parents and
childs data
> set, merging them and then comparing the responses.
>	Is there a more "elegant" or efficient approach using loops. I have
> tried using foreach with no success. I am using Stata 8.

I doubt that this needs loops at all.

One approach is to -reshape-. That has several advantages.

Otherwise, keeping the same data structure, let's suppose that we
have an indicator of parent-or-child which is say

. gen porc = mod(_n,2)

For any variable, the difference parent - child
will be

. gen diff = var - var[_n+1] if porc

and so the same response on that variable implies
-diff- being 0.

. count if diff = 0

If "response" means similarity on several variables,
then use -duplicates- to look at duplicates
in terms of a family code and those other variables.

Nick
n.j.cox@durham.ac.uk

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index