Announcement

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

  • Unknown function() error

    Hello, I am looping correlation coefficients over hundreds of variables, and am dumping outputs and variable names of the coefficient correlations into a new dta file. When trace is on, I see Stata seems to all the inputs needed to put into the new dta, but it returns function error. Below is the code, and what Stata returns to me. I've tinkered around with changing orders of the variables, it's always variable 6 that seems to catch the code.

    I've seen some help on other threads, but they don't seem to fix this one.

    set trace on

    tempname trial
    postfile `trial' coef lb up samp str20 var1 str80 varlab str20 var2 str80 valab2 using "pointbiserial.dta", replace
    quietly{
    local i=0
    foreach var of varlist re_* {
    foreach var2 of varlist pol_* {
    local i=`i'+1
    noisily: di "`i'" "-" "`var'" "-" "`var2'"

    capture esize unp `var'==`var2', pbcorr
    return list

    post `trial4' (`r(r_pb)') (`r(lb_r_pb)') (`r(ub_r_pb)') (`r(N_1)') ("`var'") ("`: var lab `var''")("`var2'")("`: var label `var2''")

    }
    }
    }
    postclose `trial'
    Stata returns: seems to correctly get all inputs

    - return list
    - post `trial4' (`r(r_pb)') (`r(lb_r_pb)') (`r(ub_
    > r_pb)') (`r(N_1)') ("`var'") ("`: var lab `var''
    > ")("`var2'")("`: var label `var2''")
    = post __000000 (.362545436385054) (.3450367943898
    > 245) (.3796625592485258) (4370) ("re_1_1_1_yr")
    > ("1.1.1: Does a legal framework for renewable en
    > ergy development exist?")("pol_flag")("polity_te
    > ntative coding (p4)")
    unknown function ()
    post: above message corresponds to expression 6,
    > variable varlab

    }
    }

  • #2
    The postnames given to postfile before the loop and post within the loop should be identical. In your case you use local macros trial and trial4. That looks like a source of problems, although even on this hypothesis the error message is puzzling. Perhaps Stata is just confused.

    Comment


    • #3
      Your code is a bit complicated and it is a bit of a headache to think through carefully what it does...

      But just a wild guess, and you can easily try whether my wild guess resolves the problem.

      Could it be that your variable label is invalid? I see something in the error message that kind of suggests to me that the variable label generated the error, and I am able to verify that if you use parenthesis in your variable labels it is a problem, see here:

      Code:
      . clear
      
      . set obs 1
      number of observations (_N) was 0, now 1
      
      . gen var = 1
      
      . la var "Bad label is Function of (4)"
      "Bad label is Function of (4) invalid name
      r(198);

      Comment


      • #4
        Originally posted by Nick Cox View Post
        The postnames given to postfile before the loop and post within the loop should be identical. In your case you use local macros trial and trial4. That looks like a source of problems, although even on this hypothesis the error message is puzzling. Perhaps Stata is just confused.
        Thank you Nick. I just fixed this typo, but I do get the same error. If you have any other ideas, I would appreciate them.

        Comment


        • #5
          Originally posted by Joro Kolev View Post
          Your code is a bit complicated and it is a bit of a headache to think through carefully what it does...

          But just a wild guess, and you can easily try whether my wild guess resolves the problem.

          Could it be that your variable label is invalid? I see something in the error message that kind of suggests to me that the variable label generated the error, and I am able to verify that if you use parenthesis in your variable labels it is a problem, see here:

          Code:
          . clear
          
          . set obs 1
          number of observations (_N) was 0, now 1
          
          . gen var = 1
          
          . la var "Bad label is Function of (4)"
          "Bad label is Function of (4) invalid name
          r(198);
          Hello Joro,
          My code loops over variables to produce point-biserial correlation coefficients. It saves the output from "return list" into a dta while running the loop.

          I have taken out all parentheses in my variable labels, but I get the same error message. Any other thoughts are greatly appreciated. Thank you.

          Comment


          • #6
            RESOLVED: I have found the error to be a typo in the spaces between the output variables in the "post" command. Lesson: very careful with spaces for post command. The other thread on Statalist with this type of error message also had a typo, their's was in this character "-".

            Thank you Nick and Joro for your help.

            Comment


            • #7
              Clara Galeazzi Thank you for posting your resolution. Can you please clarify a little. If I'm correct, your original command was
              Code:
              post `trial4' (`r(r_pb)') (`r(lb_r_pb)') (`r(ub_r_pb)') (`r(N_1)') ("`var'") ("`: var lab `var''")("`var2'")("`: var label `var2''")
              Was your problem that you didn't have spaces where I've highlighted in red? Or was it something else?

              Please note how my use of a CODE block made the command more readable than it was in your post #1. I can't speak for the other members, but I never noticed the missing spaces when reading post #1. Please take a look at the Statalist FAQ linked to from the top of the page. It explains this and more in sections 9-12 on how to best pose your question to Statalist. The more you help others understand your problem, the more likely others are to be able to help you solve your problem.


              Comment

              Working...
              X