Announcement

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

  • Stata program - syntax specification problem

    Hi Stata Users!

    I have the following lines of program. The program itself seems to work, but for some reason I encounter a problem of syntax specification, when I try to run it.
    Is it possible to have a variable list and number as an input? Or it could be a problem with e()/r() class conflict within the program, as well?

    Thank you very much for your answers in advance!

    Lorand

    program bootstrap123, eclass

    version 13
    syntax varlist(min=2 numeric) namelist(max=1 numeric) [, ESTIMATES]
    gettoken y x: varlist
    local sizeofvar: list sizeof x
    local sizeofvar1 = sizeofvar + 1
    quietly reg `y' `x'
    mat coef1=e(b)
    mat coef3=J(`namelist',`sizeofvar1',.)
    foreach i of numlist 1/`sizeofvar1' {
    forvalues v = 1/`namelist' {
    bsample _N
    quietly reg `y' `x'
    mat coef2_`v'=e(b)
    mat coef3[`v',`i'] = coef2_`v'[1,`i']
    }
    }
    svmat coef3, names(col)
    mat std1=J(`namelist',`sizeofvar1',.)

    foreach i of numlist 1/`sizeofvar1' {
    quietly sum c`i'
    mat std1[1,`i']=r(sd)
    }

    mat output = coef1 \ std1
    mat list output

    if "`estimates'" == "estimates" {
    mat list coef3
    }


    drop c*

    end

  • #2
    Hi Lorand,

    I don't think you can specify both "varlist" AND "namelist" in the "syntax" statement. The documentation says "namelist is an alternative to varlist".
    I would just rewrite it to be an option instead, e.g.

    Code:
    syntax varlist(min=2 numeric), NROWS(integer) [ESTIMATES]
    ...
    mat coef3=J(`nrows',`sizeofvar1',.)
    ...
    David.

    Comment


    • #3
      Hi David,

      Thanks for the answer.

      Your suggestion must work. However, the constraint here is that I have to specify the program inputs as kind of expression list, so the the variables and the number should be included in the main syntax and not in the option part.

      Could it be done in that way?

      Lorand

      Comment


      • #4
        Code:
        local sizeofvar1 = sizeofvar + 1
        looks like another bug to me.

        Comment


        • #5
          Hi Lorand,
          Possibly, with a bit of manipulation (e.g. creating a variable to hold a constant number, including it in the varlist, separating it out afterwards and using "summarize" on it). But I'm intrigued to know more about your situation. Why do you have this particular constraint?
          Thanks,
          David.

          Comment

          Working...
          X