Forum Replies Created

Viewing 15 posts - 16 through 30 (of 76 total)
  • Author
    Posts
  • Attaullah Shah
    Moderator
    Post count: 76

    Here is something you can work with. I tried to find the colvector for variable names, but did not find. But I was in hurry, you may find it somewhere in the gtools documentations.

    sysuse auto, clear
    gstats tab price mpg, by(foreign strvar) matasave
    
    * Get the statistics matrix from the GstatsOutput class
    * Note: We need to convert the real matrix to string first
    mata stat_values = strofreal(GstatsOutput.output)
    
    * Get the names of the statistics
    mata stat_names = GstatsOutput.statnames
    
    * Combine the two matrices
    mata outtable = stat_names \ stat_values
    
    * Add the matrix to asdocx system
    flexmat reset
    flexmat addmat, matname(outtable) 
    
    * Export to word
    asdocx export
    
      0 |1            2             3          4          5             6 
    ----+------------------------------------------------------------------
      1 |n          sum          mean        min        max            sd 
    ----+------------------------------------------------------------------
      2 |4        19162        4790.5       3799       6486      1169.903 
      3 |4           93         23.25         19         26       3.40343 
      4 |2         9129        4564.5       4195       4934      522.5519 
      5 |2           42            21         18         24      4.242641 
      6 |8        47741      5967.625       3667      14500      3579.357 
      7 |8          153        19.125         14         24      3.758324 
      8 |27      178391      6607.074       3291      15906      3661.267 
      9 |27         513            19         12         29      4.085622 
     10 |9        52934      5881.556       3829       8814      1592.019 
     11 |9          166      18.44444         14         28      4.585605 
     12 |2         8409        4204.5       3984       4425      311.8341 
     13 |2           64            32         30         34      2.828427 
     14 |1        12990         12990      12990      12990             . 
     15 |1           14            14         14         14             . 
     16 |3        14486      4828.667       3895       6295      1285.613 
     17 |3           70      23.33333         21         26      2.516611 
     18 |9        56353      6261.444       3995       9735      1896.092 
     19 |9          224      24.88889         21         30      2.713137 
     20 |9        56634      6292.667       3748      11995      2765.629 
     21 |9          237      26.33333         17         41      9.367497 
    -----------------------------------------------------------------------
    
    Attaullah Shah
    Moderator
    Post count: 76

    The use of both \indent and \i directives simultaneously is currently not supported. However, it is on my to-do list for future updates. Additionally, the addition of formatting directives for table headers is also not yet available. The text formatting directives were added specifically for text and paragraphs, see [ details here ].

    Attaullah Shah
    Moderator
    Post count: 76

    Ozer Erdem
    I have updated asdocx. It now fixes the decimal points problem in the ttest results. You should now be able to see accurate decimal points in your results.

    Additionally, for very small values, using the c#_disfmt(%9.4e) format is a better way to report values in exponential format. For example, instead of seeing 0.00000009 , you would see 9.00e-08. This helps in making the results easier to read and understand.

    asdocx_update 

    Here is an example:

     * Create a dummy dataset
    clear
    input float group double score
    1 .0000012
    1 .000015
    1 .0000214
    2 .011
    2 .039
    2 .0610
    end
    
    * Report 7 decimal places for the column 4
    asdocx ttest score,  replace  c4_dec(7) by(group) stat(obs mean t)
                                     Table: Results
      0 |1                             2          3              4          5           6 
    ----+------------------------------------------------------------------------------------------
      1 |                          obs1       obs2          Mean1      Mean2      t_value 
    ----+------------------------------------------------------------------------------------------
      2 |score by group: 1 2           3          3      0.0000125      0.037      -2.556 
    -----------------------------------------------------------------------------------------------
    
    * Report exponential format for column 4
    asdocx resetfmt
    
    asdocx ttest score,  replace  tzok c4_disfmt(%9.4e) by(group ) stat(obs mean t)
    
    Two-sample t test with equal variances
    ------------------------------------------------------------------------------
       Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
    ---------+--------------------------------------------------------------------
           1 |       3    .0000125    5.96e-06    .0000103   -.0000131    .0000382
           2 |       3        .037    .0144684    .0250599   -.0252523    .0992523
    ---------+--------------------------------------------------------------------
    combined |       6    .0185063     .010501     .025722   -.0084873    .0454999
    ---------+--------------------------------------------------------------------
        diff |           -.0369875    .0144684               -.0771581    .0031831
    ------------------------------------------------------------------------------
        diff = mean(1) - mean(2)                                      t =  -2.5564
    Ho: diff = 0                                     degrees of freedom =        4
    
        Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
     Pr(T < t) = 0.0314         Pr(|T| > |t|) = 0.0629          Pr(T > t) = 0.9686
    
    
       
                                       Table: Results
      0 |1                             2          3             4          5           6 
    ----+----------------------------------------------------------------------------------------
      1 |                          obs1       obs2         Mean1      Mean2      t_value 
    ----+----------------------------------------------------------------------------------------
      2 |score by group: 1 2       3.000      3.000      1.25e-05      0.037      -2.556 
    ---------------------------------------------------------------------------------------------
    Notes:
    
    Attaullah Shah
    Moderator
    Post count: 76
    in reply to: number formatting #17605

    As mentioned here, permanent options are set only in the asdocx_defaults.ado file. Other options, such as decimal points, fonts, and number formatting, are either specific to a particular command or specific to the Stata session. These session-specific options will reset to the default values when Stata is restarted. If you’ve been running Stata for several days without shutting down your computer, these options might have remained in the memory. At any point in your Stata session, if you wish to reset these formattings to default, you may use the command

    asdocx resetfmt
    Attaullah Shah
    Moderator
    Post count: 76

    Support for confidence intervals with survey data has been added. Try this example after updating.

    asdocx_update 
    
    * Results from the Stata command  
    svy: tabulate  diabetes race  , row  ci 
    
    ----------------------------------------------------------------------
    Diabetes  |                            Race                           
    status    |         White          Black          Other          Total
    ----------+-----------------------------------------------------------
     Not diab |         .8812          .0931          .0257              1
              | [.8437,.9107]   [.0705,.122]  [.0111,.0586]               
              | 
     Diabetic |         .8203          .1647          .0151              1
              | [.7476,.8755]  [.1203,.2213]  [.0033,.0668]               
              | 
        Total |         .8791          .0955          .0253              1
              | [.8407,.9093]  [.0725,.1249]  [.0108,.0585]               
    ----------------------------------------------------------------------
    
    * In asdocx, we need to write the treatment variable first 
    asdocx svy: tabulate race diabetes, row  ci  template(table1) replace cat(% ci)  
    Table 1: Demographics
    Variables White (n=9065) Black (n=1086) Other (n=200) P-value
    Diabetes status 0.000
    Not diabetic
    88.121% (84.370 – 91.068) 9.308% (7.045 – 12.201) 2.571% (1.106 – 5.862)
    Diabetic
    82.028% (74.756 – 87.553) 16.467% (12.027 – 22.134) 1.505% (0.325 – 6.680)
    P-values by t-test for continuous variables and Chi2 test for binary/categorical variables. * Design-based Pearson Chi2 test p-value
    Attaullah Shah
    Moderator
    Post count: 76




    I have added the requested feature. First update asdocx with

    asdocx_update

    . Here is an example.

    * Create a toy example
    *generate random number of observations
    clear 
    set obs 200
    
    * create variable for using sleeping pills
    gen use_pills = round(runiform(0,1))
    label define use_pills 0 "Yes" 1 "No"
    label val use_pills use_pills
    label var use_pills "Used sleeping pills in the last month"
    
     *create variable for male and female
    gen gender = round(runiform(0,1))
    label define gender 0 "Female" 1 "Male"
    label val gender gender
    replace use_pills = 1 if gender == 1 & use_pills == 0 & runiform()<0.7
    replace use_pills = 0 if gender == 0 & use_pills == 1 & runiform()<0.3
    

    Row percentage with confidence intervals


    * if row percentages are required

    asdocx tab use_pills gender, template(table1) row cat(% ci) replace 
    Table 1: Demographics
    Variables Yes (n=79) No (n=121) Total (200) P-value
    gender 0.000
    Female
    64.444% (53.921 - 73.735) 35.556% (26.265 - 46.079) 100.000%
    Male
    19.091% (12.731 - 27.622) 80.909% (72.378 - 87.269) 100.000%
    P-values by t-test for continuous variables and Chi2 test for binary/categorical variables.
    * If the total column is not required, use option nototal
    * Add option table_layout(auto) for auto adjust columns for contents
    asdocx tab use_pills gender, template(table1) row cat(% ci) /// 
    replace nototal table_layout(auto)
    Table 1: Demographics
    Variables Yes (n=79) No (n=121) P-value
    gender 0.000
    Female
    64.444% (53.921 - 73.735) 35.556% (26.265 - 46.079)
    Male
    19.091% (12.731 - 27.622) 80.909% (72.378 - 87.269)
    P-values by t-test for continuous variables and Chi2 test for binary/categorical variables.

    Column percentages

    * If col percentages 
    asdocx tab use_pills gender, template(table1) col categorical(% ci) replace 
    Table 1: Demographics
    Variables Yes (n=79) No (n=121) Total (200) P-value
    gender 0.000
    Female
    73.418% (62.455 - 82.097) 26.446% (19.294 - 35.097) 45.0% (38.203 - 51.989)
    Male
    26.582% (17.903 - 37.545) 73.554% (64.903 - 80.706) 55.0% (48.011 - 61.797)
    P-values by t-test for continuous variables and Chi2 test for binary/categorical variables.

    Attaullah Shah
    Moderator
    Post count: 76

    I have not personally used table1 in my research. Can you advise me if it is appropriate to report confidence intervals for categorical variables?

    Attaullah Shah
    Moderator
    Post count: 76

    I was previously using an older version of missings that I downloaded from SSC. However, the latest version available on the Stata Journal website at dm0085_2 from http://www.stata-journal.com/software/sj20-4 has the new option identify(). To get the updated version that works with asdocx, type the following in Stata command window:

    net install asdocx_missings, from(http://fintechprofessor.com) replace

    After the update, the option identify() should work.

    webuse nlswork
    asdocx missings table, identify(race) replace
    Checking missings in all variables: 15082 observations with missing values
    race
    # of missing values white black other Total
    0 9604 3709 139 13452
    1 9672 3966 152 13790
    2 677 278 9 964
    3 199 89 3 291
    4 25 7 0 32
    5 1 1 0 2
    6 2 1 0 3
    Total 20180 8051 303 28534
    Notes:
    Attaullah Shah
    Moderator
    Post count: 76

    Please post the code that you used. I searched for the identify option in missings , but did not find anything related to it.

    Attaullah Shah
    Moderator
    Post count: 76

    I am happy to announce the missings is now supported in asdocx, see details here .

    Attaullah Shah
    Moderator
    Post count: 76

    This is one of the un-documented directive. When asdocx tries to convert flexmat file into MS Word or other formats, it examines each cell of the matrix for the \indent_# directive. Here, # represents the number of spaces that should be added before the text in that cell. For example, if a cell starts with \indent_4 , it will add four spaces before the text.
    You may also like to check text directors to format text, see this page.

    Example

    flexmat reset 
    asdocx setfile, save(indent.html) replace
    flexmat addrow, data(Variables, Frequencies)
    flexmat addrow, data(Gender :) row(2)
    flexmat addrow, data(\indent_4 Male, 655) row(3)
    flexmat addrow, data(\indent_4 Female, 745) row(4)
    asdocx export
    
    Table: Results
    Variables Frequencies
    Gender :
    Male
    655
    Female
    745
    Notes:
    Attaullah Shah
    Moderator
    Post count: 76

    I am happy to announce that asdocx now supports mrtab program that is written by Ben Jann. Adding mrtab was quite a laborious task. I had to assemble the result matrices from various components, which required a significant amount of time. See details here https://asdocx.com/asdocx-with-mrtab-tabulates-multiple-responses-in-stata-asdoc/

    Attaullah Shah
    Moderator
    Post count: 76

    I am happy to announce that asdocx now supports fre program that is written by Ben Jann. See details here https://asdocx.com/use-fre-with-asdocx-in-stata/

    Attaullah Shah
    Moderator
    Post count: 76

    I like the idea of creating such a list.
    Adding support for user-written programs to asdocx can be straightforward if the program produces its results in the form of macros, scalars, or matrices. However, if this is not the case, it would be equivalent to writing the user’s program from scratch. I am always available to assist other asdocx users who would like to add support for community-contributed packages to asdocx. I can share the template file and provide guidance on how to use it to add programs to asdocx.

    Attaullah Shah
    Moderator
    Post count: 76

    I took some time today to update flexmat. The addparts sub-command now accurately adds notes and titles to the tables that are appended using the appendmat command. I have updated the provided example to reflect these changes.

Viewing 15 posts - 16 through 30 (of 76 total)