asdocx: Export from Stata to Word, Excel, LaTeX & HTML Forums asdocx Forum ttest – number format with large numbers (exponential notation)

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • Daniel Paschek
    Participant
    Post count: 6

    Dear Dr. Shah,

    my dataset contains many large numbers (8 digits and more, e.g. 20,000,000 million Euros).
    When performing ttests, for instance, I thus often get the number format of the Mean or SD in exponential notation.
    Is there way to fix this?

    In a related topic, is possible to add the significance stars to the ttest statistic, without creating the table row by row (as listed here https://asdocx.com/2019/09/10/customized-tables-using-option-row-of-asdoc-stata/) ?

    Many thanks

    Daniel Paschek
    Participant
    Post count: 6

    In a related issue with t-tests, I get the following error message:

               asdocxtable():  3301  subscript invalid
                     <istmt>:     -  function returned error

    My code is:

    asdocx ttest OtherVC_EquityInv if VCType == "OtherVC", ///
        by(EPU_AbAvgYear) unpaired unequal stat(mean sd obs) label abb(.)  save(test)

    The error only occurs when I include “sd” in the stat option. It also occurs when I use asdoc.
    Is there a way to fix this?

    Dr. Attaullah Shah
    Keymaster
    Post count: 106

    Hello Daniel
    Concerning the error, please update asdocx with

    asdocx_update

    and it should fix the error.

    To solve the formating issue, please use tzok option with format(%20.3f) or any other valid Stata format. See the following example

    sysuse auto
    replace price = price * 1000000
    asdocx ttest price if make != "Toyota Corona", label abb(.)  save(test) format(%20.3f) replace tzok
    Table: Results
    
     ---+---------------------------------------------------------------------------------------------
      1 |                    obs                  Mean                St_Err      t_value      p_value 
    ----+---------------------------------------------------------------------------------------------
      2 | Price           73.000        6171369863.014         347546171.778       17.757        0.000 
    --------------------------------------------------------------------------------------------------

    The following tables shows examples of different available formatting options.

         Four values displayed in different numeric display formats
        +---------------------------------------------------------------------+
        |   %9.0g   %9.0gc     %9.2f     %9.2fc %-9.0g       %09.2f     %9.2e |
        |---------------------------------------------------------------------|
        |   12345   12,345  12345.00  12,345.00  12345    012345.00  1.23e+04 |
        |  37.916   37.916     37.92      37.92  37.916   000037.92  3.79e+01 |
        | 3567890  3567890  3.57e+06   3.57e+06  3567890   3.57e+06  3.57e+06 |
        |   .9165    .9165      0.92       0.92  .9165    000000.92  9.16e-01 |
        +---------------------------------------------------------------------+
    
    Greg Hebb
    Participant
    Post count: 3

    I am getting the same error when using ttest. I updated asdocx but the problem still exists. When I run with asdoc, it works fine. Any suggestions?

    Dr. Attaullah Shah
    Keymaster
    Post count: 106

    Hello Greg Hebb
    Can you please post an example data and code so that I replicate the issue at my end.

    Greg Hebb
    Participant
    Post count: 3

    Thanks. So I have simplied my dataset to the following:

    input float assets byte bankparent
    .001	0
    .001	0
    .0011	0
    .0011	0
    .0011	1
    .0011	1
    .0011	1
    .0607	1
    .0605	1
    end

    If I use asdoc, I get no errors and the following output:

    asdoc ttest assets , by(bankparent)  replace dec(4) ///
           stat(obs mean dif  p) title(T-Test of differences for all Funds) ///
          save(table1all.doc)
    
    Two-sample t test with equal variances
    ------------------------------------------------------------------------------
       Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
    ---------+--------------------------------------------------------------------
           0 |       4      .00105    .0000289    .0000577    .0009581    .0011419
           1 |       5       .0249    .0145745    .0325896   -.0155653    .0653653
    ---------+--------------------------------------------------------------------
    combined |       9       .0143    .0087499    .0262497   -.0058773    .0344773
    ---------+--------------------------------------------------------------------
        diff |             -.02385    .0165259               -.0629277    .0152277
    ------------------------------------------------------------------------------
        diff = mean(0) - mean(1)                                      t =  -1.4432
    Ho: diff = 0                                     degrees of freedom =        7
    
        Ha: diff <; 0                 Ha: diff != 0                 Ha: diff > 0
     Pr(T > t) = 0.0961         Pr(|T| > |t|) = 0.1922          Pr(T > t) = 0.9039
    
                        T-Test of differences for all Funds
    
    ------------------------------------------------------------------------------------------
                           |      obs1       obs2      Mean1      Mean2        dif    p_value 
    -----------------------+------------------------------------------------------------------
    assets by bankparent   |                                                                  
                       0 1 |         4          5       .001       .025      -.024       .192 
    ------------------------------------------------------------------------------------------

    (note: file table1all.doc not found)
    Click to Open File: table1all.doc

    If I use the same data and options but instead use asdocx, I get the following output:

    asdocx ttest assets , by(bankparent) replace dec(4) stat(obs mean dif p) title(T-Test of differences for all Funds) save(table1all.doc)

    – local AllowedStats “mean se df obs t p sd dif”
    – if !`: list stats in local(AllowedStats)'{
    = if !1{
    display as error “Error in the statistics(`statistics’) option!”
    display as text “only the following statistics are allowed”
    display as result “`AllowedStats'”
    exit
    }
    – else loc statsOptions “stat(`stats’)”
    = else loc statsOptions “stat( obs mean dif p )”
    – set trace off
    option T-Test not allowed
    r(198);

    If I remove all options, I get:

    asdocx ttest assets , by(bankparent)
    – local AllowedStats “mean se df obs t p sd dif”
    – if !`: list stats in local(AllowedStats)'{
    = if !1{
    display as error “Error in the statistics(`statistics’) option!”
    display as text “only the following statistics are allowed”
    display as result “`AllowedStats'”
    exit
    }
    – else loc statsOptions “stat(`stats’)”
    = else loc statsOptions “stat()”
    – set trace off

    Two-sample t test with equal variances
    ——————————————————————————
    Group | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]
    ———+——————————————————————–
    0 | 4 .00105 .0000289 .0000577 .0009581 .0011419
    1 | 5 .0249 .0145745 .0325896 -.0155653 .0653653
    ———+——————————————————————–
    combined | 9 .0143 .0087499 .0262497 -.0058773 .0344773
    ———+——————————————————————–
    diff | -.02385 .0165259 -.0629277 .0152277
    ——————————————————————————
    diff = mean(0) – mean(1) t = -1.4432
    Ho: diff = 0 degrees of freedom = 7

    Ha: diff < 0 Ha: diff != 0 Ha: diff > 0
    Pr(T < t) = 0.0961 Pr(|T| > |t|) = 0.1922 Pr(T > t) = 0.9039

    Two-sample t test with equal variances

    —————————————————————————————————————————
    | obs1 obs2 Mean1 Mean2 dif St_Err t_value p_value p_value
    ———————–+—————————————————————————————————
    assets by bankparent |
    0 1 | 4 5 .001 .025 -.024 .0165 -1.45 .192 .
    —————————————————————————————————————————
    asdocxtable(): 3301 subscript invalid
    <istmt>: – function returned error
    r(3301);

    .

    Dr. Attaullah Shah
    Keymaster
    Post count: 106

    Hello Greg Hebb
    Thanks for reporting this. I have fixed the bug. Please update asdocx and try the following two examples;

    asdocx_update
    *When using the stat() option
    asdocx ttest Asset , by(bankparent)  replace dec(4)  /// 
        stat(obs mean dif  p) title(T-Test of differences for all Funds) ///
       save(table1all.doc)
    ----+----------------------------------------------------------------------------------------
      1 |                         obs1      obs2     Mean1     Mean2       dif     p_value 
    ----+----------------------------------------------------------------------------------------
      2 |Asset by bankparen~1         4         5     0.001     0.025    -0.024      0.192 
    ---------------------------------------------------------------------------------------------
    
    
    * When option stat() is not used
    asdocx ttest Asset , by(bankparent)  replace dec(4)        ///
        title(T-Test of differences for all Funds) ///
        save(table1all.doc)
    
    
    ----+-------------------------------------------------------------------------------------------
      1 |                       obs1    obs2   Mean1   Mean2     dif    St_Err   t_value    p_value 
    ----+-------------------------------------------------------------------------------------------
      2 |Asset by bankparen~1       4       5   0.001   0.025  -0.024    0.0165     -1.45     0.192 
    ------------------------------------------------------------------------------------------------
    
    Greg Hebb
    Participant
    Post count: 3

    This fixed the problem, thank you very much.

    Daniel Paschek
    Participant
    Post count: 6

    Dear Dr. Shah,

    after updating asdocx I now get the following error message: “conformability error”.
    I am running a unequal unpaired t-test with the the stat() option:

    asdocx ttest CompanyAge if InvRec == 1 & (VCType == "GVC" | VCType == "IVC"), by(VCType) 
    > unpaired unequal replace dec(3) stat(obs mean se sd dif t p)  title(T-Test - GVCs vs. IVCs )  lab
    > el abb(.) save(VCInv_GVCIVC_ttest_All)  
    

    The output is the following:

    
    Two-sample t test with equal variances
    ------------------------------------------------------------------------------
    Variable |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
    ---------+--------------------------------------------------------------------
         GVC |   1,072    5.757696    .2418861    7.919692    5.283071     6.23232
         IVC |   7,379    6.221168    .0935548    8.036464    6.037774    6.404562
    ---------+--------------------------------------------------------------------
    combined |   8,451    6.162377     .087271    8.022764    5.991305     6.33345
    ---------+--------------------------------------------------------------------
        diff |           -.4634723    .2621968               -.9774422    .0504976
    ------------------------------------------------------------------------------
        diff = mean(GVC) - mean(IVC)                                  t =  -1.7677
    Ho: diff = 0                                     degrees of freedom =     8449
    
        Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
     Pr(T < t) = 0.0386         Pr(|T| > |t|) = 0.0772          Pr(T > t) = 0.9614
    conformability error
    r(503);
    
    end of do-file
    
    r(503);
    
    

    Would be great if you could assist

    Dr. Attaullah Shah
    Keymaster
    Post count: 106

    I have fixed the issue. please update asdocx

    asdocx_update
    Daniel Paschek
    Participant
    Post count: 6

    Awesome, works perfectly – thank you so much!

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.