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

st: Local macros and strings: yet another query...

From   Höchle, Daniel (MI Switzerland) <>
To   <>
Subject   st: Local macros and strings: yet another query...
Date   Tue, 24 Jun 2008 10:26:34 +0200

Dear all,

Thanks a lot to Sergiy and Nick for their answers. Unfortunately, the project I am currently working on urges me to generate a series of variables on an observation-by-observation basis. The problem is highly iterative. As such the time t-1 value of variable A impacts on the time t value of variable B which in turn determines the time t value of variable A, etc.

The strings I want to evaluate have to be constructed by loops since the number of options varies across "myCommand". Interestingly, however, my "loop strings" do not work with Sergiy's solution whereas for the manually constructed strings his solution works perfectly. Here is an illustration of the problem:

-- snip --

  sysuse sp500, clear
  * This is the manual version of the string:
  local ManualStr "myCommand, Opt1(\`Val1') Opt2(\`Val2')"
  * Here, the string is replicated by looping through a forval loop:
  local LoopStr "myCommand,"
  forval j=1/2 {
      local LoopStr "`LoopStr' Opt`j'(\`Val`j'')"
  * Let's assume we want to evaluate "myCommand" for the following values:
    local t = 122
    local Val1 = close[`t']
    local Val2 = volume[`t']
* Display the resulting ManualStr:
  disp `"`ManualStr'"'   // this is what I would expect

* Display the resulting LoopStr
  disp `"`LoopStr'"'     // there is a problem: where is `Val1'???

-- snip --

Result: Somehow Stata drops `Val1' from the "LoopStr" whereas `Val1' is contained in the "ManualStr" as it should. Therefore, I wonder whether there is a problem in my way of constructing "LoopStr" or if this is a Stata problem? I use Stata SE 9.2.

Once more thanks a lot for looking into this issue in advance.

Best regards,


Any information in this communication is confidential and may be privileged or otherwise protected from disclosure without our consent. If you are not the intended recipient, you are not authorised to and must not disclose, copy, distribute, or retain this message or any part of it. You are requested to please telephone or email the sender and delete this message and any attachment from your system.
Due to the electronic nature of e-mail, there is a risk that the information contained in this message has been modified. Consequently we can accept no responsibility or liability as to the completeness or accuracy of the information.

*   For searches and help try:

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