Statalist


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

st: RE: simple data input question- expanding macros


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: simple data input question- expanding macros
Date   Fri, 15 Aug 2008 18:07:56 +0100

Apart from comments already made, I can see further issues here. 

One is that there may be some confusion here between -input- and -input
<varlist>-. 

That aside, I suspect that pgscooter has been bitten by a bug. -input-
can't deal with local macros and indeed makes a hash of them. 

. clear

. local gold "gold"

. input str4  what

          what
  1. `gold'
  2. "`gold'"
  3. end

. l

     +------+
     | what |
     |------|
  1. |    ` |
  2. | `gol |
     +------+

. replace what = "`gold'" in 1
(1 real change made)

. l

     +------+
     | what |
     |------|
  1. | gold |
  2. | `gol |
     +------+

I suspect that most of the code for -input- is very old and may even
predate all of that for local macros. I could buy an argument that,
retrospectively at least, -input- is regarded as a place where local
macros shouldn't work. But making a hash of them looks like a bug. 

Even if I'm right, it's not very surprising that it hasn't surfaced
before now. 

A different comment is this: I've seen a few postings recently from
people who appear to be starting on Stata and starting to learn Stata
programming at the same time. That's rather puzzling to me. Stata
programming can be great fun, sometimes the most fun you can have
without laughing, but only exceptionally should someone need to start on
both at the same time. Those who program should make it possible for the
rest of you not to do so. It's particularly unfortunate if people get
the impression that each task requires a new program to automate it.
Stata really shouldn't be that difficult! (Nor is it SAS.) 

Nick 
[email protected] 

[email protected]

I would like to input data that I have in strings manually in a .do
file.
That is, say I have a for loop going through a list of a bunch of
strings, how can I use those strings to input data?

Say, I have a macro called color.
and, I have an existing dataset with blue and green as observations
(there is only one variable, COL).
Why doesn't the following work:

local color = "red"
input
`color'
end

I tried the above code using a global variable as well, to no avail:

global color = "red"
input
${color}
end


Is there a better way to do this? How do I expand my macro before
anything else happens?

*
*   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