|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Question: postfile with variable number variables
Dear all,
My apologies for a previous version of this e-mail that contained an
attached file. This was a handling error.
Please find below the answer to my question. Many thanks to Alan Riley
for responding.
Best wishes
Eve
Eve,
I saw your message on Statalist regarding -post- with a variable number
of variables.
Your code was close to having everything it needed. The only
thing left to do is to build up a macro containing _all_ of
the values you wish to post, rather than building up separate
macros for each item you wish to post. Try the following, and
if it works for you, perhaps we can report back to Statalist that
this is what was needed in case anyone else is interested in
a similar solution in the future:
local variable_list "var1 var2 var3"
local no_var: word count `variable_list'
postfile postname `variable_list' using filename, replace
local to_post // make sure to_post is empty just to be safe
forvalues i=1(1)`no_var'{
local topost "`to_post' (`i')"
}
post postname `to_post'
postclose postname
The above code will put the following in to_post at each of the three
loop iterations:
iteration 1: (1)
iteration 2: (1) (2)
iteration 3: (1) (2) (3)
Then, when you call -post-, to_post will be substituted in place to
make the command
post postname `to_post'
post postname (1) (2) (3)
Sincerely,
Alan Riley
StataCorp LP
Vice President of Software Development
[email protected]
979-696-4600
979-696-4601 (fax)
http://www.stata.com/
*
* 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/