Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create list that preserve macro and colon

    Hi, I am trying to create a weird list to use in a gmm estimation command of this form `dv':varname for many variables (with a space in between). Specifically, I wanna create a list and put it in a macro like:
    Code:
    local linear weight length turn
    foreach var of local linear {
    local coef_linear "`coef_linear'" "`"`"dv"'"':`var' "
    }
    di "`coef_linear'"
    macro list
    and then use this list to run in an estimation like:
    Code:
    gmm gmm_reg2, nequations(1) parameters(`coef_linear' `dv':_cons) ///
                instruments(weight length turn) mylhs(`dv') nolog
    But as you can see the problem is that this macro can't be use in the command because typing `coef_linear' would not give me the same results and the display command show. The -macro list- command confirms this. I have been struggle to get around this issue, and furthermore to better understand how to manipulate list effectively using nested macros. I was wondering if you anyone could give me some suggestions? I guess the main difficulty is to preserve the quote ` ' and the colon in the macro

    Thanks so much!

  • #2
    All of the quotation marks and compound double quotes in your -local- command are unnecessary and getting in the way. It should be:

    Code:
    local linear weight length turn
    foreach var of local linear {
        local coef_linear `coef_linear' dv:`var'
    }
    di "`coef_linear'"
    macro list

    Comment


    • #3
      Hi Clyde,

      Thank you for your comment. I see your point. However, I would like to get the list where dv is in a quotation indicating macro because I am writing a program and would like be able to replace dv by any dependent variables. So I would like to get the list like this:
      Code:
      `dv':weight `dv':length `dv':turn
      Do you think there is a way to get around it?
      Thanks

      Comment


      • #4
        Opps sorry, I think I found away to get around it. Probably I won't have to do this if I plug in a string for `dv' before creating this list. That way I won't have to deal with quotes along with the colon. But I would be great if somebody could suggest a general solution in creating list that nest macro quotes like this.

        Thanks a lot!

        Comment


        • #5
          Try this:
          Code:
          local linear weight length turn
          local moq = char(96)
          local mcq = char(39)
          set tracedepth 1
          set trace on
          foreach var of local linear {
              local coef_linear `macval(coef_linear)' `moq'dv`mcq':`var'
          }
          macro list
          
          local dv test_dv
          display `"`coef_linear'"'

          Comment


          • #6
            This works perfectly! I have learnt some new tricks.
            Thank you so much Clyde!

            Comment

            Working...
            X