[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Danielle H.Ferry" <dferry@gc.cuny.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: if command |

Date |
Thu, 12 Feb 2004 23:32:24 -0500 |

Hmm, actually, perhaps I should have been more clear on what I am doing here. I am not actually using the values of the variable <aRate> in these statements. The basic idea is I want to run essentially the same procedure several times on different variables. There are style-type things I want to change depending on what that variable is (i.e. title on graph), so I write conditions to differentiate between the relevant variable. So, a snipped version of my program would look like this:

program test

...

if `1'==aRate {

local title = "Abortion rate"

}

if `1'==bRate {

local title = "Birth rate"

}

...

end

The argument `1' is either aRate or bRate.

Danielle Ferry

On Feb 12, 2004, at 5:02 PM, David Kantor wrote:

At 03:26 PM 2/12/2004 -0500, Danielle Ferry wrote:Can anyone please explain when the if command requires quotes around the expression and when it does not?As far as I know, if you are comparing to a string constant, you need quotes.

For example, I've found the following seemingly quirky behavior:

1) if "`1'"=="aRate" | "`1'"=="bRate" | "`1'"=="pRate" --> requires quotes

2) if `1'==aRate --> does not require quotes

3) if "`1'"=="apRatio" --> requires quotes

Example 2 probably ought to have quotes if it is meant to test a string value. It would, however, pass as a legitimate expression if...

aRate happens to be a variable name and...

it is numeric and so is `1' (that is the contents of the local 1), or

it is string, and `1' contains enclosing quotes (I haven't tried this), or

it is either numeric or string, and `i' is also a variable name of a compatible type.

But in these cases, you are implicitly testing observation 1, which you might not have intended.

Example 2 would also pass if aRate is a scalar and `1' is numeric (and if `1' is a variable name, then you are testing observation 1).

In any case, while Example 2 might sometimes pass, it is probably not doing what you intended.

I hope this helps.

-- David

David Kantor

Institute for Policy Studies

Johns Hopkins University

dkantor@jhu.edu

410-516-5404

*

* For searches and help try:

* http://www.stata.com/support/faqs/res/findit.html

* http://www.stata.com/support/statalist/faq

* http://www.ats.ucla.edu/stat/stata/

* * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**Re: st: Stata corrupting data?***From:*Alexandra Kalev <akalev@princeton.edu>

**st: Stata corrupting data?***From:*"Deborah Garvey" <DGarvey@scu.edu>

**Re: st: if command***From:*David Kantor <dkantor@jhu.edu>

- Prev by Date:
**st: RE: Getting at value labels** - Next by Date:
**Re: st: Stata corrupting data?** - Previous by thread:
**Re: st: if command** - Next by thread:
**st: Re: Stata corrupting data?** - Index(es):

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