Announcement

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

  • Error in expression

    Hello,

    I am created a local variable `tif' which loops over around 45 terms (string).

    local tif "0"
    foreach var of varlist item101-item145 {
    local iic "(1.7*`var'a)^2*(1/(1+exp(-1.7*`var'a*(x-`var'b))))*(1-(1/(1+exp(-1.7*`var'a*(x-`var'b)))))"
    local tif "`tif'+ `iic "
    }


    This `tif' is a mathematical expression in terms of x. I then code:
    twoway (function `tif', range(-5 5))

    All these run fine. However the moment I add another term in the loop say item146, I get an error : "error in expression"

    error in expression: 0+ (1.7*item101a)^2*(1/(1+exp(-1.7*item101a*(x-item101b))))*(1-(1/(1
    > +exp(-1.7*item101a*(x-item101b)))))..........


    Is this because the function has increased its maximum length? I am not sure what the problem is.






  • #2
    The length of your final expression is nowhere near the maximum allowable length of either a macro or an expression. But, I think you have breached the limit of 300 numeric literals in an expression. (And you are also perilously close to, but not over, the limit of 800 dyadic operators.)

    Comment


    • #3
      My guess is that the underlying problem would be much easier after a reshape long

      Comment


      • #4
        Hello,
        I reshaped my data and it makes sense to run the command after reshaping. However, I am still getting the same error. I think it is because of some limit in a function/ expression or something which is still not clear to me.
        My data set includes only two variables a and b and this is the command I use -

        Code:
        local tif "0"
        forvalues i = 1/39 {
            local iic "(1.7*a[`i'])^2*(1/(1+exp(-1.7*a[`i']*(x-b[`i']))))*(1-(1/(1+exp(-1.7*a[`i']*(x-b[`i'])))))"
            local tif "`tif'+ `iic' "
            }
        
        
        local se "1/sqrt(`tif')"
        
        twoway (function `tif' , range(-5 5)) ///
            (function `se', range(-5 5) yaxis(2)), ///
            xtitle("Theta") ytitle("I(Theta)") title("Test Information") ytitle("Standard Error", axis(2)) ///
            legend(order(1 "Test Information" 2 "Expected Standard Error"))
        It works as long as I am iterating over 38 `i' observations.If I increase the values to 39 or anything above that, it gives me "error in expression"

        Comment


        • #5
          I think that you are exceeding the limitation on the number of pairs of nested parentheses in an expression. I am not sure of this, because I do not know if this limit (249) refers to depth of nesting, or total number of nested sets of parentheses even if they are in separate groups that do not nest in each other.



          Comment


          • #6
            Thank you Clyde Schechter . The problem indeed was with paranthesis. I created new variables and then summed them before plotting them which reduced the number of operators.

            Comment

            Working...
            X