Statalist


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

st: using if sentences in Stata


From   Linn Renée Naper <[email protected]>
To   <[email protected]>
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/



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