Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: string with embedded blanks in logical expression

From   "Stephen R. Hale" <[email protected]>
To   "STATA" <[email protected]>
Subject   st: string with embedded blanks in logical expression
Date   Wed, 8 Jun 2005 11:24:04 -0400

Hi all,

Perhaps someone can help me with this problem?

I have a location field in the data editor with many records for Fishing
Island, New Hampshire and Tizzard Island, Maryland.

I used

. levels location, local(uniqloc) separate(,)

When I display I get
. display "`uniqloc'"
The return (in green type on the monitor) has each element in compound
double quotes and each element separated with a comma.
. `"Fishing Island, New Hampshire"',`"Tizzard Island, Maryland"'

Then I use a foreach loop to sequentially use each element in the local
. foreach locat of local uniqloc {

If I display the value contained in locat
. display "`locat'"
Then the return is
. Fishing Island, New Hampshire
Which is exactly as it appears in the Data Editor

However, if I try all this in an ado file including the regression below ...
. regress pccov shootden if location == `"`locat'"'
Then I get no observations, even though I know there are observations.

If I type into the command window
. regress pccov shootden if location == `"`locat'"'
Then it works fine.

What's the difference?  Where am I going wrong?



Stephen R. Hale, Ph.D.
Complex Systems Research Center
Institute for Study of Earth, Oceans, and Space
Morse Hall
University of New Hampshire
Durham, NH 03824-3525
Work 603.862.4758
Fax  603.862.0188
Home 603.664.4036
[email protected]

*   For searches and help try:

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