Statalist


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

AW: AW: st: round () if


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   AW: AW: st: round () if
Date   Fri, 6 Feb 2009 17:20:04 +0100

<> 


You can nest those -cond()-s, see
http://www.stata-journal.com/sjpdf.html?articlenum=pr0016




HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Shehzad Ali
Gesendet: Freitag, 6. Februar 2009 17:16
An: [email protected]
Betreff: Re: AW: st: round () if

Thank you, Jeph and Martin. This was really helpful.

To add further, is it possible to add another condition to round off weeks 
> 0 and <1.5 to become 1 instead of zero while keeping the previous 
condition alive?

Regards,
Shehzad

On Feb 6 2009, Martin Weiss wrote:

>
><> 
>
>Good solution, and in one line. Careful with 1 and 2, though. Does Ali
>really want them to become zero?
>
>*************
>clear*
>set obs 30
>gen weeks=_n
>gen newweek=cond(abs(round(week,12)-week)<=2,round(week,12),week)
>list
>*************
>
>
>
>HTH
>Martin
>
>
>-----Ursprüngliche Nachricht-----
>Von: [email protected]
>[mailto:[email protected]] Im Auftrag von Jeph Herrin
>Gesendet: Freitag, 6. Februar 2009 16:56
>An: [email protected]
>Betreff: Re: st: round () if
>
>
>Assuming your week is integers
>
>  gen newweek=cond(abs(round(week,12)-week)<=2,round(week,12),week)
>
>should do.
>
>hth,
>Jeph
>
>
>Shehzad Ali wrote:
>> Hi listers,
>> 
>> I want to round a variable 'week' if it is within 2 weeks range of 
>> multiples of 12 week. So 10 weeks should become 12 weeks while 9 weeks 
>> should not change. Similarly 21 weeks would not change while 25 weeks 
>> will change to 24 weeks. Is there a way to do it in Stata using -round- 
>> or other command?
>> 
>> Thank you,
>> Shehzad
>> *
>> *   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/
>

-- 
Shehzad I Ali
Department of Social Policy & Social Work
University of York
YO10 5NG
+44 (0) 773-813-0094



*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index