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, is already up and running.

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

Re: st: If variable x contains variable y

From   Nick Cox <>
Subject   Re: st: If variable x contains variable y
Date   Sun, 15 Jul 2012 18:56:01 +0100

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


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:

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