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

  • Evaluating linear expressions for tests of coefficients

    I am writing an .ado file to calculate tests of coefficients similar to -test-. I cannot use the code of -test- or -lrtest- directly because the test is not a Wald test nor a likelihood ratio test.

    I need to evaluate whether the expressions involving the coefficients are well formed and linear (in the coefficients). Does anyone know of code in Stata or Mata which will help me do that?

    I looked at -test.ado- hoping to lift some of its code, but the part which evaluates expressions is in the built-in command -_test-. Similarly -constraint-, which also evaluates linear expressions, is a built-in command. -egen- commands allowing expressions generally pass them to built-in commands like -summarize-.

    I am realizing this is a tricky task because I need to allow expressions like "1/3*_b[length]" but reject expressions like "1/_b[length]".

    John Gallup

  • #2
    Writing a parser for linear expressions in Stata would be tricky. I imagine it can be done, but it would not be the best tool for the job. A simpler approach would be running the expression through -capture test- and then checking the return code. If it's not a well-formed linear expression, -test- will return error code 131/ If -test- doesn't find an error, it's a well formed linear expression and you can then move on to the rest of your code.
    Last edited by Clyde Schechter; 22 Nov 2016, 22:30. Reason: Correct grammatical errors


    • #3
      Thanks Clyde for the excellent suggestion. Following it up, I realized that I can use -constraints- and -makecns- to create the R matrix of linear constraints. The parsing of the constraints to make sure they are well formed and linear comes from the -makecns- command, not the -constraints- commmand. See an example of the application in