Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: If variable x contains variable y


From   <[email protected]>
To   <[email protected]>
Subject   Re: st: If variable x contains variable y
Date   Sun, 15 Jul 2012 19:08:48 +0100

Great, thanks Nick. I hadn't considered doing it that way, it makes perfect sense.


Thanks for you help,
John

>>> Nick Cox  15/07/12 6:57 PM >>>
I think you should look at saving the mother ids as a separate dataset
and then a -merge- back in to see what matches.

The key point you seem to be missing is that by default -if- applies
only to what is true of the _same observation_ (row, case, record).
You want -if- to apply anywhere in the same dataset and that is a real
stretch.

Nick

On Sun, Jul 15, 2012 at 6:03 PM,   wrote:

> Sorry, not quite. I'll try and explain it a slightly different way. I
> was "x" to be 1 when the idno in the variable idno can also be found in
> the variable mother_id. So each instance in "idno" where the "mother_id"
> is not missing indicates a child, and a reference to the "idno" that
> represents their mother. Therefore, the same number can appear in both
> columns, but they will be on different rows. I want to know which idnos
> in "idno" are mothers, therefore represented in "mother_id" as well. I
> hope that makes more sense.
> Thanks,
> John
>
>>>> Christoph Engel  15/07/12 5:43 PM >>>
> John,
>
> So you want your dummy to be 1 whenever "mother_id" is not missing,
> right? Provided "mother_id" is a numeric variable, the following does
> the trick
>
> gen dummy = (mother_id < .)
>
> Should mother_id be a string variable, the following syntax should work
>
> gen dummy = (mother_id != "")
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index