Announcement

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

  • Problem with Customizable Table

    Dear all,

    I am trying to create a customizable table based on the video from the stata blog
    https://blog.stata.com/2021/08/24/cu...istical-tests/.

    However, I keep getting this error message - "keyword command requires option command()". I am unable to figure what is wrong with my code

    Below is my code:

    ttest age, by(mcdexpand2021)
    return list
    table (command) (result), command(ttest white_nh, by(mcdexpand2021))
    table (command) (result),
    command(Non-Expansion = r(mu_1)
    Expansion = r(mu_2)
    Diff = (r(mu_2)-r(mu_1))
    pvalue = r(p)
    : ttest white_nh, by(mcdexpand2021))


    I am just learning how to use Stata, I would really appreciate your help.

    Warm regards
    Tolu

  • #2

    I think your second call to table is split over several lines, but
    without line continuation comment indicators. Your code
    Code:
    table (command) (result),
    command(Non-Expansion = r(mu_1)
    Expansion = r(mu_2)
    Diff = (r(mu_2)-r(mu_1))
    pvalue = r(p)
    : ttest white_nh, by(mcdexpand2021))
    should be
    Code:
    table (command) (result),               ///
        command(Non-Expansion = r(mu_1)     ///
            Expansion = r(mu_2)             ///
            Diff = (r(mu_2)-r(mu_1))        ///
            pvalue = r(p)                   ///
            : ttest white_nh, by(mcdexpand2021))
    I added indentation to help us see that this is command was split into
    multiple lines.

    Here is a similar example to the original, but using the publicly
    available auto data.
    Code:
    sysuse auto
    ttest mpg, by(foreign)
    return list
    table (command) (result), command(ttest mpg, by(foreign))
    table (command) (result), ///
        command( ///
            NotForeign=r(mu_1) ///
            Foreign=r(mu_2) ///
            Diff = (r(mu_2)-r(mu_1)) ///
            pvalue = r(p) ///
            : ttest mpg, by(foreign))
    Here is the log from running the above.
    Code:
    . sysuse auto
    (1978 automobile data)
    
    . ttest mpg, by(foreign)
    
    Two-sample t test with equal variances
    ------------------------------------------------------------------------------
       Group |     Obs        Mean    Std. err.   Std. dev.   [95% conf. interval]
    ---------+--------------------------------------------------------------------
    Domestic |      52    19.82692     .657777    4.743297    18.50638    21.14747
     Foreign |      22    24.77273     1.40951    6.611187    21.84149    27.70396
    ---------+--------------------------------------------------------------------
    Combined |      74     21.2973    .6725511    5.785503     19.9569    22.63769
    ---------+--------------------------------------------------------------------
        diff |           -4.945804    1.362162               -7.661225   -2.230384
    ------------------------------------------------------------------------------
        diff = mean(Domestic) - mean(Foreign)                         t =  -3.6308
    H0: diff = 0                                     Degrees of freedom =       72
    
        Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
     Pr(T < t) = 0.0003         Pr(|T| > |t|) = 0.0005          Pr(T > t) = 0.9997
    
    . return list
    
    scalars:
                  r(level) =  95
                     r(sd) =  5.785503209735139
                   r(sd_2) =  6.611186898567625
                   r(sd_1) =  4.743297247514701
                     r(se) =  1.362162113622176
                    r(p_u) =  .9997372920330829
                    r(p_l) =  .0002627079669171
                      r(p) =  .0005254159338342
                      r(t) =  -3.630848447731832
                   r(df_t) =  72
                   r(mu_2) =  24.77272727272727
                    r(N_2) =  22
                   r(mu_1) =  19.82692307692308
                    r(N_1) =  52
    
    . table (command) (result), command(ttest mpg, by(foreign))
    
    (very wide output omitted)
    
    . table (command) (result), ///
    >         command( ///
    >                 NotForeign=r(mu_1) ///
    >                 Foreign=r(mu_2) ///
    >                 Diff = (r(mu_2)-r(mu_1)) ///
    >                 pvalue = r(p) ///
    >                 : ttest mpg, by(foreign))
    
    ---------------------------------------------------------------------
                           |  NotForeign    Foreign       Diff     pvalue
    -----------------------+---------------------------------------------
    ttest mpg, by(foreign) |    19.82692   24.77273   4.945804   .0005254
    ---------------------------------------------------------------------

    Comment


    • #3
      Thanks Jeff. It worked.

      Comment

      Working...
      X