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: generating variable if condition met
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: generating variable if condition met
Date
Thu, 5 Jul 2012 14:15:57 +0200
On Thu, Jul 5, 2012 at 1:56 PM, Caliph Omar Moumin wrote:
> There is a string variable ‘hproblem’ containing diseases classification, which has codes from 1- 436.
> I want to generate a variable ‘type’ which is ‘hproblem’ classified into two; 1 for group1 and 0 for group2.
> The following codes of the variable ‘hproblem’ required to be included in group1
> 1-50, 53-103, 124-165, 167, 171, 175 -182, 188-200, 223-252, 257, 262-287, 313-336, 356-362
> AND ALL THE REST in group two.
> Is there a simple way to generate variable ‘type’?
It is typically more useful to define such indicator variables as 0, 1
rather than 1, 2, so that is the solution I give:
gen byte type = inrange(hproblem, 1, 50) | ///
inrange(hproblem, 53, 103) | ///
inrange(hproblem, 124, 165) | ///
inrange(hproblem, 175, 182) | ///
inrange(hproblem, 188, 200) | ///
inrange(hproblem, 223, 252) | ///
inrange(hproblem, 262, 287) | ///
inrange(hproblem, 313, 336) | ///
inrange(hproblem, 356, 362) | ///
inlist( hproblem, 167, 171, , 257) ///
if !missing(hproblem)
For more see:
<http://www.stata.com/support/faqs/data-management/true-and-false/>
and
Nicholas J. Cox (2006) Stata tip 39: In a list or out? In a range or
out? The Stata Journal, 6(4):593--595.
<http://www.stata-journal.com/article.html?article=dm0026>
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/