Announcement

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

  • Student t distribution function

    I am translating some R code (lines 92-96 for the curious) to calculate some confidence intervals, and I'm gifted with the following syntax
    Code:
    lb <- att - qt(1-alpha/2,df=K-1)*se
    The thing to focus on here is everything in the parentheses. According to Statology . com,

    The function qt returns the value of the inverse cumulative density function (cdf) of the Student t distribution given a certain random variable x and degrees of freedom df.
    I'm only vaguely familiar with Stata syntax for distributions and that sort of thing. Might there be an equivalent for this function in Stata?

  • #2
    I think this would be -invt(K-1, 1-alpha/2)- in Stata. [I don't know R, I'm relying here on the description you show from Statology.com.]

    Comment


    • #3
      The related function is

      Code:
      help invttail()
      Code:
      sysuse auto
      regress mpg weight disp
      di _b[weight] - invttail(e(df_r),0.05/2)*_se[weight]
      Res.:

      Code:
      . regress mpg weight disp
      
            Source |       SS           df       MS      Number of obs   =        74
      -------------+----------------------------------   F(2, 71)        =     66.79
             Model |  1595.40969         2  797.704846   Prob > F        =    0.0000
          Residual |  848.049768        71  11.9443629   R-squared       =    0.6529
      -------------+----------------------------------   Adj R-squared   =    0.6432
             Total |  2443.45946        73  33.4720474   Root MSE        =    3.4561
      
      ------------------------------------------------------------------------------
               mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
            weight |  -.0065671   .0011662    -5.63   0.000    -.0088925   -.0042417
      displacement |   .0052808   .0098696     0.54   0.594    -.0143986    .0249602
             _cons |   40.08452    2.02011    19.84   0.000     36.05654    44.11251
      ------------------------------------------------------------------------------
      
      .
      . di _b[weight] - invttail(e(df_r),0.05/2)*_se[weight]
      -.00889252
      Note: Crossed with #2.
      Last edited by Andrew Musau; 26 Aug 2022, 12:44.

      Comment


      • #4
        If you use -invttail()- instead of my proposal of -invt()-, you will, for typical values of alpha, get a negative number returned, which will mean that the value of lb (which I'm guessing from context stands for lower bound of a confidence interval) will be higher than the value of att. You could, however, use -invttail(K-1, alpha/2)-, which would give the same result as -invt(K-1, 1-alpha/2)-.

        Comment


        • #5
          lower bound of a confidence interval) will be higher than the value of att
          Indeed you are correct, I was perplexed at first when my lower bounds were higher than the counterfactual, and my higher bounds were lower than the counterfactual. Either way, this helps, so thank you both so much!

          Comment

          Working...
          X