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

From |
Linn Renée Naper <linn.naper@ecgroup.no> |

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

Subject |
st: using if sentences in Stata |

Date |
Thu, 27 Nov 2008 18:12:06 +0100 |

Hi I am trying to program a "double if-sentence" in Stata. Is this possible? And what do I do wrong here? Here is what I write. The results is that Stata only performs the commands after the second "else": replace flow=`cable_cap'. if shift==-1 {{ if (flow[_n-1] + `cap')<`add' { replace flow= (-1*`cap') } else { replace flow=flow[_n-1]-`add' } } else { if (flow[_n-1] - `cap')>`add' { replace flow=`cap' } else { replace flow=flow[_n-1]+`add' } } I thus try to write a command where the executed command if the result (if shift==-1) is true also includes an if-formulation, and the same with the executed command in the case where the result of the initial criterion is false. If the shift value is -1, what I do with the variable flow depends on whether the sum (flow[_n-1]+`cap') is larger or smaller than the value given in `add'. Similarly, if the shift variable isn't -1 but 1, what I do with flow depends on the sum (flow[_n-1]-`cap') and whether this sum is smaller or larger than the value given by `add'. I appreciate any suggestions on how this command should best be writte. Thanks! Linn * * 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**:**st: RE: using if sentences in Stata***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: using if sentences in Stata***From:*Maarten buis <maartenbuis@yahoo.co.uk>

**st: RE: using if sentences in Stata***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**st: lincom after nlsur** - Next by Date:
**st: RE: using if sentences in Stata** - Previous by thread:
**st: lincom after nlsur** - Next by thread:
**st: RE: using if sentences in Stata** - Index(es):

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