Announcement

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

  • Automating specific type of table output via asdoc, nested

    Hello,
    would it be possible to create a custom table, that looks like the following picture, automatically using asdoc [nested] command?
    Click image for larger version

Name:	sshot.png
Views:	1
Size:	16.4 KB
ID:	1736957

    Either way would be fine. The latter might be easier (?) since asdoc, nested automatically puts the indices in columns when using bys Index command.
    Currently the nested results table looks like this for regression 1:
    Click image for larger version

Name:	1streg.png
Views:	1
Size:	34.0 KB
ID:	1736958

    I need to run 3 regressions per time period chosen. I can get the nested tables with
    Code:
    bys Index: asdoc reg y x1 x2 x3 x4 x5, replace nested
    bys Index: asdoc reg y x1 x2 x3 x4 x5 x6 x7, append nested
    bys Index: asdoc reg y x1 x2 x3 x4 x5 x6 x7 x8 x9, append nested
    I am only interested in x1, x2, and x3 coefficients (and their significance indicated by stars, standard errors in parenthesis). When using the above command the nested table gives out all coefficients, and append command just adds the full new regression to the file instead of appending one table.

    I am aware that I can use
    Code:
    asodc, accum(bys Index: asdoc reg y x1 x2 x3 x4 x5 x6 x7 x8 x9)
    to store these values in a macro, but I do not know how I would use the macro to implement the desired changes.
    So is there a way to automate these tables so I wouldn't have to do the tables manually as the datasets are various and large? I am using Stata 18, and installed asdoc from ssc.
    Thank you in advance.
    Here is a data example of a dataset (there are dummies in, hence one that has value 0 in the snippet):
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(Date Index) float(x1 x2) double x3 float x4
      1.13616e+12  1   .007612212    .003968798 -.37 0
      1.13616e+12  2   .007612212    .021190444 -.37 0
      1.13616e+12  3   .007612212    .011272166 -.37 0
      1.13616e+12  4   .007612212     .01488089 -.37 0
      1.13616e+12  5   .007612212    .008910405 -.37 0
      1.13616e+12  6   .007612212   -.012066815 -.37 0
      1.13616e+12  7   .007612212    .004117139 -.37 0
      1.13616e+12  8   .007612212     .01015796 -.37 0
      1.13616e+12  9   .007612212    .012511847 -.37 0
      1.13616e+12 10   .007612212    .004153495 -.37 0
      1.13616e+12 11   .007612212             . -.37 0
    1.1362464e+12  1  .0007993703   -.003317988 -.22 0
    1.1362464e+12  2  .0007993703    .008408818 -.22 0
    1.1362464e+12  3  .0007993703   .0018131792 -.22 0
    1.1362464e+12  4  .0007993703    .004257003 -.22 0
    1.1362464e+12  5  .0007993703    .007241737 -.22 0
    1.1362464e+12  6  .0007993703  -.0006748497 -.22 0
    1.1362464e+12  7  .0007993703   .0007140059 -.22 0
    1.1362464e+12  8  .0007993703    -.02648982 -.22 0
    1.1362464e+12  9  .0007993703    .014410613 -.22 0
    1.1362464e+12 10  .0007993703    .002391231 -.22 0
    1.1362464e+12 11  .0007993703             . -.22 0
    1.1363328e+12  1  -.005995332    .008140917 -.42 0
    1.1363328e+12  2  -.005995332   -.004962879 -.42 0
    1.1363328e+12  3  -.005995332   -.007884173 -.42 0
    1.1363328e+12  4  -.005995332   -.003643263 -.42 0
    1.1363328e+12  5  -.005995332    -.00333417 -.42 0
    1.1363328e+12  6  -.005995332   .0021392643 -.42 0
    1.1363328e+12  7  -.005995332   -.018333698 -.42 0
    1.1363328e+12  8  -.005995332   -.013252933 -.42 0
    1.1363328e+12  9  -.005995332   -.011053025 -.42 0
    1.1363328e+12 10  -.005995332   -.003967269 -.42 0
    1.1363328e+12 11  -.005995332             . -.42 0
    1.1364192e+12  1 -.0017573863    .014447698  .67 0
    1.1364192e+12  2 -.0017573863   .0005946556  .67 0
    1.1364192e+12  3 -.0017573863  -.0015456794  .67 0
    1.1364192e+12  4 -.0017573863    -.00960754  .67 0
    1.1364192e+12  5 -.0017573863   -.008007395  .67 0
    1.1364192e+12  6 -.0017573863    -.00941605  .67 0
    1.1364192e+12  7 -.0017573863   -.005993012  .67 0
    1.1364192e+12  8 -.0017573863    .005240256  .67 0
    1.1364192e+12  9 -.0017573863    .004420996  .67 0
    1.1364192e+12 10 -.0017573863     .00548491  .67 0
    1.1364192e+12 11 -.0017573863             .  .67 0
    1.1366784e+12  1  .0026801866     .00695249 -.21 0
    1.1366784e+12  2  .0026801866 -.00031961536 -.21 0
    1.1366784e+12  3  .0026801866    .008680353 -.21 0
    1.1366784e+12  4  .0026801866 .000014676232 -.21 0
    1.1366784e+12  5  .0026801866    .002981023 -.21 0
    1.1366784e+12  6  .0026801866    .008782237 -.21 0
    end
    format %tc Date

  • #2
    While I don't fully understand your specific needs, I suspect one of these options may be helpful:

    Use the wide option.
    Refer to the asdoc help file, specifically the regression section. (You can access it by entering the code help asdoc.)
    Use the drop() option within the nested table.

    If none of these suggestions meet your requirements, you may need to explore asdocx.
    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

    Comment


    • #3
      Thank you for the answer. To summarize my needs: can I add different regression results into one nested table automatically using append or rowappend commands? Now If I run the three regressions and append the results with the code I provided I get three tables. I only need to keep three coefficients from each regression (x1, x2, and x3+R-squared+no. obs.) and would need them to be in one table. Is this possible in asdoc or even in asdocx? Could I store the results of the regressions to accum() and paste only the needed information from there?

      Comment


      • #4
        Here is a solution that utilizes asdocx. This solution employs flexmat, which is a component of the asdocx system. flexmat is used in this context to merge the three tables generated by asdocx. There are numerous other applications for flexmat, which you can find in the detailed documentation.
        1. I begin by generating three nested regression tables using the reset option of asdocx.
        2. Subsequently, I merge the three tables in two stages: initially, I merge the last two tables, followed by the merged table with the first one.
        3. Ultimately, I export the merged table to Excel, which I had specified in the initial asdocx code. Since the table is very large, I chose Excel, but you can choose Word, HTML, or LaTeX.
        4. If a transposed version of the table is required, you can append transpose to the asdocx reg ... lines at the end.


        Code:
        * Make the first set of regressions, keep only required variables
        
        bys Index: asdocx reg y x1 x2 x3 x4 x5, nested keep(x1 x2 x3) replace save(f1.xlsx) 
        
        * Another set of regression, but in a new table
        bys Index: asdocx reg y x1 x2 x3 x4 x5 x6, reset nested keep(x1 x2 x3) 
        
        * The third table
        bys Index: asdocx reg y x1 x2 x3 x4 x5 x6 x7, reset nested keep(x1 x2 x3)  
        
        * Merge the first two tables
        flexmat merge, matloc(2, 3)
        
        flexmat merge, matloc(1, 2)
        
        * Export the file to Excel or Word
        asdocx export
        Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	152.4 KB
ID:	1737062
        Regards
        --------------------------------------------------
        Attaullah Shah, PhD.
        Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
        FinTechProfessor.com
        https://asdocx.com
        Check out my asdoc program, which sends outputs to MS Word.
        For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

        Comment


        • #5
          For those who want to replicate the above example, use the following code for generating the dummy data. The data posted by Silas is incomplete.
          Code:
          asdocx_update
          clear
          set obs 100
          gen x1=uniform()
          gen x2=uniform() 
           gen x3=uniform()
          
          gen x4=uniform() 
          gen x5=uniform()
          gen x6=uniform() 
          gen x7=uniform()
          gen y=uniform() +x1+x2+x3+x4+x5+x6+x7
          
          gen Index = mod(_n, 5)
          
          bys Index: asdocx reg y x1 x2 x3 x4 x5, nested keep(x1 x2 x3) replace save(f1.xlsx) 
          
          * Another set of regression, but in a new table
          bys Index: asdocx reg y x1 x2 x3 x4 x5 x6, reset nested keep(x1 x2 x3) 
          
          * The third table
          bys Index: asdocx reg y x1 x2 x3 x4 x5 x6 x7, reset nested keep(x1 x2 x3)  
          
          * Merge the first two tables
          flexmat merge, matloc(2, 3)
          
          flexmat merge, matloc(1, 2)
          
          * Export the file to Excel or Word
          asdocx export
          Regards
          --------------------------------------------------
          Attaullah Shah, PhD.
          Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
          FinTechProfessor.com
          https://asdocx.com
          Check out my asdoc program, which sends outputs to MS Word.
          For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

          Comment


          • #6
            I am sorry if my data was incomplete, I thought I had provided a proper glance as to what type of my data was. The asdocx command seems like just the thing I am looking for! Just one question, as there are 11 indices (times 3 for 3 regressions) if they merge into Index being on columns, and regression coefficients in the rows I will run into issues with fitting in one page. Can the asdocx transpose the results i.e., have the variables x1, x2 etc. where there is now the Index signifier (1), (2), (3) etc. and vice versa, so that the table would be longer instead of wider? And I'd like to thank you again for being so kind as to provide even examples of how one could resolve this type of issue.

            Comment

            Working...
            X