Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
<john.guzek@lshtm.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: If variable x contains variable y |

Date |
Sun, 15 Jul 2012 17:31:55 +0100 |

Hi, Sorry, this is getting somewhat embarrassing. Apparently the legible table is not in this chain, so I'll add it again. idhouse |idno |mother_id |x 1 |73664 |. |1 1 |73665 |. |. 1 |73666 |. |. 1 |73667 |73664 |. 1 |73668 |. |. 2 |94038 |. |. 2 |94039 |. |1 2 |94040 |. |. 2 |94041 |. |1 2 |94042 |. |. 2 |94043 |. |1 2 |94044 |94041 |. 2 |94045 |94039 |. 2 |94046 |. |1 2 |94047 |94046 |. 2 |94048 |94046 |. 2 |94049 |. |. 2 |94050 |. |. 2 |94051 |94043 |. 2 |94052 |. |. John >>> 15/07/12 5:30 PM >>> Hi, Sorry, I've not explained this very well. Hopefully the legible version of the table will help, which I resent. So yes, "y" represents "idno", "z" represents "mother_id". I'm trying to make "x" to identify the mothers in "idno". So x=1 if "y" is found anywhere in "z". Thanks for you help. John >>> Christoph Engel 15/07/12 5:18 PM >>> John, It still is not fully clear to me what you want. I take it what you previously called "y" is variable "idno". You actually want a dummy that is 1 if "idno" is in a certain range, and 0 otherwise. If that is what you are after, you can use gen dummy = (idno > 173664 & idno < 294053) Actually for that purpose it is better that your variable idno is numeric. Hope that helps Christoph Engel Am 7/15/2012 5:52 PM, schrieb john.guzek@lshtm.ac.uk: > Hi, > > > Thanks for your help. It's a bit more tricky than that, at least as far > as I can tell. I'll try and explain a little more clearly! So, as below, > I have household level and individual level identifiers. I essentially > want to flag the mother's idno. So something along the lines of gen x=1 > if idno=="any value in mother_id" to look like column x below. Whether > column x read 1 or the corresponding idno is not important at this > stage. And I agree, these probably should be stored as string, it's not > my data! > > > idhouseidnomother_idx > 1736641 > 173665 > 173666 > 17366773664 > 173668 > 294038 > 2940391 > 294040 > 2940411 > 294042 > 2940431 > 29404494041 > 29404594039 > 2940461 > 29404794046 > 29404894046 > 294049 > 294050 > 29405194043 > 294052 > > > > Thanks for your help! > John > > > >>>> Christoph Engel 15/07/12 4:21 PM>>> > John, > > You will have to define the value of x if y does not fulfil your > condition, i.e. if it is not equal to z. Depending on your purposes you > might either want it to be a missing value, or some expression of x, say > > 0. I would therefore start out > > gen x = . > replace x = y if y == z > > (note the "==" in the if clause) > > Best > > Christoph Engel > > Am 7/15/2012 4:59 PM, schrieb Steve Nakoneshny: >> John, >> >> At first glance, it would seem that -gen x = y if y = z- would serve > as a solution. Of course, this assumes that your I'd vars are numerical > and not string vars (which they probably should be stored as). >> Steve >> >> Sent via carrier pigeon >> >> On 2012-07-15, at 8:52 AM, "john.guzek@lshtm.ac.uk" wrote: >> >>> Hello, >>> >>> >>> This is my first time using statalist, I hope I do this all > correctly! >>> >>> I'm looking to create a variable x which is equal to y, but only if > the given value for y can be found in another variable, z. These are all > id numbers, so say y is a universal id and z is a mother's id, telling > you the universal id of the mother in relation to the child. >>> >>> For example: >>> >>> >>> yzx >>> >>> >>> 1.. >>> 2.2 >>> 3.3 >>> 42. >>> 5.. >>> 6.. >>> 737 >>> 8.. >>> 9.. >>> 107. >>> >>> >>> So I'm trying to figure out how to create x. Any help would be much > appreciated. >>> >>> Thanks, >>> John >>> >>> >>> * >>> * 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/ >> > -- _________________________________________________________________ Prof. Dr. Christoph Engel Max-Planck-Institut zur Erforschung von Gemeinschaftsgütern Max Planck Institute for Research on Collective Goods Kurt-Schumacher-Strasse 10 D 53113 Bonn Tel. +49/228/91416-10 Fax +49/228/91416-11 e-mail:engel@coll.mpg.de http://www.coll.mpg.de http://www.coll.mpg.de/engel.html http://ideas.repec.org/e/pen22.html http://papers.ssrn.com/sol3/cf_dev/AbsByAuth.cfm?per_id=251559 _________________________________________________________________ * * 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/ * * 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/

**Follow-Ups**:**Re: st: If variable x contains variable y***From:*Christoph Engel <engel@coll.mpg.de>

- Prev by Date:
**Re: st: If variable x contains variable y** - Next by Date:
**Re: st: If variable x contains variable y** - Previous by thread:
**Re: st: If variable x contains variable y** - Next by thread:
**Re: st: If variable x contains variable y** - Index(es):