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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

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

Subject |
st: RE: using if sentences in Stata |

Date |
Thu, 27 Nov 2008 18:20:17 +0100 |

Line for the server... First impression: Are you sure the first line " if shift==-1 {{" needs two curlies? I cannot figure out what the second one is doing... Try your luck without it and report back to the list. HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Linn Renée Naper Sent: Thursday, November 27, 2008 6:12 PM To: statalist@hsphsun2.harvard.edu Subject: st: using if sentences in Stata 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/ * * 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: RE: using if sentences in Stata***From:*Linn Renée Naper <linn.naper@ecgroup.no>

**References**:**st: using if sentences in Stata***From:*Linn Renée Naper <linn.naper@ecgroup.no>

- Prev by Date:
**st: using if sentences in Stata** - Next by Date:
**st: RE: creating variable containing number of children** - Previous by thread:
**st: using if sentences in Stata** - Next by thread:
**st: RE: RE: using if sentences in Stata** - Index(es):

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