Announcement

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

  • Invalid Syntax when calling for local variable

    Hello, I am getting an invalid syntax error when I am try the following: I want ci to be summed only if n values are from the local i025. Could someone point me in the right direction on how to call for this variable?

    local numst=42
    local i025=floor(0.025*(`numst'-1))
    local i975=ceil(0.975*(`numst'-1))
    local i05=floor(0.050*(`numst'-1))
    local i95=ceil(0.950*(`numst'-1))

    quietly sum alpha
    display as text "Difference in Differences coefficient=" as result _newline(2) r(mean)

    sort asim
    sum ci if _n==`i025'

  • #2
    I don't see anything wrong with this code. My guess is that you are running it incorrectly. When code creates and then uses local macros, you must run the entire block of code without interruption. If you do it line-by-line, or even just run some of it and then try to run the rest separately, the local macros go out of scope. When that happens, a command like -sum ci if _n == `i025'- looks to Stata like -sum ci if _n ==-, which is, indeed, invalid syntax.

    I want ci to be summed only if n values are from the local i025.
    I don't get what this means. The local i025 contains a single number (in fact, that number is 1). So the command -sum ci if _n == `i025'- will "summarize" the data in the first observation in the data set.

    Comment


    • #3
      That was in fact my error. I was running the code by each line to check my work. When I run the code entirely together it worked. Thank you.

      Comment

      Working...
      X