Announcement

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

  • t-test of the hypothesis that the population mean is equal to a specified value given by a scalar

    I want to run a t-test that the population mean is equal to a specified value given by a scalar. For example, the sample of the population is given by the variable "mpg" and the scalar has the name "alpha" and is equal to 23.

    However, using the syntax
    Code:
    ttest mpg == alpha
    yields "variable alpha not found".

    Using the syntax
    Code:
    ttest mpg == `alpha'
    yields "invalid syntax"

    While using the syntax
    Code:
    ttest mpg == 23
    works.

    How can I make "ttest" read the numerical value of the scalar "alpha"?

  • #2
    You can't. -ttest- requires a number, and a scalar is not a number from a syntactic perspective. Using `alpha' doesn't work because `' is the way to dereference local macros, but not scalars. But you were on the right track. What you need to do is copy the value of scalar alpha into a local macro, and then use the local macro in your ttest command.

    Code:
    local alpha = scalar(alpha)
    ttest mpg = `alpha'
    That said, I would recommend that rather than creating alpha as a scalar, create it as a local macro in the first place.

    Comment


    • #3
      Thanks Clyde! I have already tried to read and understand "Macro — Macro definition and manipulation" in the manual. But it's hopeless to me! 20 pages written as if the author wants to keep his secrets. Do you have perhaps a literature recommandation for the topic "Stata macros"?

      Comment


      • #4
        There are a number of book on learning to use Stata. You can search for them on, for example, Amazon or Barnes and Noble, but the easiest place to find them is on the StataCorp website in their bookstore. There are several, oriented towards users with different disciplinary backgrounds and different levels of prior statistical and programming experience. Perhaps you can find one there that will suit your needs.

        Comment

        Working...
        X