Statalist


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

Re: st: Question: postfile with variable number variables


From   Eve CORDA <[email protected]>
To   [email protected]
Subject   Re: st: Question: postfile with variable number variables
Date   Mon, 06 Apr 2009 11:59:28 +0200

Dear all,

Please find below the answer to my question that was nicely provided by Alan Riley, whom I thank a lot.

Best wishes,

Eve
--- Begin Message ---
From   Alan Riley <[email protected]>
To   Eve CORDA <[email protected]>
Subject   Re: st: Question: postfile with variable number variables
Date   Fri, 3 Apr 2009 19:06:18 -0500
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/


--- End Message ---



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