Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: identifying the unique values across variables and creating new var equal to them


From   "Lacy,Michael" <Michael.Lacy@colostate.edu>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: identifying the unique values across variables and creating new var equal to them
Date   Thu, 28 Feb 2013 18:01:32 +0000

>From 	  "Ivanova, K.O." <K.O.Ivanova@uva.nl>
>To 	  "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
>Subject 	  st: identifying the unique values across variables and creating new var equal to them
>Date 	  Wed, 27 Feb 2013 12:19:34 +0000
>
>Dear all,
>
>I have a dataset where each row corresponds to a couple. Each partner within a couple was asked to
>report the birthdates of his / her children (not specified whether own or step). I need to find a way
>to identify the cases when one partner reported a birthdate which the other partner did not (this is
>the only way for me to identify children born outside the current union).

(snip, snip)

Given Katya's data:

clear
input id ch1 ch2 ch3  par_ch1 par_ch2 par_ch3
1 3 9 12  7  9  12 
2 2 5 3  .  .  .
3 9 11 7  7  4  11
end
compress

Here's another approach, a pretty common "while not found search" approach:
//
gen byte found = .
foreach c of varlist ch* {
   replace found = 0
   foreach p of varlist par* {
      replace found =  1 if (found ==0)  & (`c' == `p') 
   }
   gen byte own_`c' = `c' if !found
}
list

If each partner is not also a subject in the data set, this would need to be 
ruan again with the role of c and p reversed.

Regards,

Mike Lacy
Dept. of Sociology
Colorado State University
Fort Collins CO 80523 USA



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index