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

st: RE: using if sentences in Stata

From   "Martin Weiss" <>
To   <>
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.


-----Original Message-----
[] On Behalf Of Linn Renée Naper
Sent: Thursday, November 27, 2008 6:12 PM
Subject: st: using if sentences in Stata


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.


*   For searches and help try:

*   For searches and help try:

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