Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Cond() and if - Help


From   "Scott Merryman" <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Cond() and if - Help
Date   Sat, 11 Aug 2007 09:44:41 -0500

It would be good see how you used -cond()-.

I believe this one-line statement would work:

replace var1 = cond(var2<= var3 & var4 ==1 & var5 == `i', 0 , ///
cond(var3>var2& var2<= X & var4 ==1 & var5 == `i', 1, ///
cond(var3 > X & var4 ==1 & var5 == `i', 2,var1)))

Or:

replace var1 = cond(var2<= var3 ', 0 , ///
cond(var3>var2& var2<= X , 1, ///
cond(var3 > X , 2,var1))) ///
if & var4 ==1 & var5 == `i'

However, it might easier to read the do-file with multiple -replace- statements.

Scott



On 8/11/07, tiago.pereira@incor.usp.br <tiago.pereira@incor.usp.br> wrote:
> Dear statalisters,
>
> I would like to know whether there is a way to run the same analysis below
> using one line only. If not, what would be the shorter way to do it?
>
> I tried cond() but could not include all statements together.
>
>
> replace var1 = 0 if var2<=var3&var4==1&var5==`i'
> replace var1 = 1 if var2>var3&var2<=X&var4==1&var5==`i'
> replace var1 = 2 if var2>X&var4==1&var5==`i'
>
> Thank you for your time and help
>
> all the best,
>
> Tiago
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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