Announcement

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

  • Using -asdoc- to export a local -matrix-

    Dear Statalisters,

    I want to export regression results in a neat table. I am using a -matrix- to extract specific scalars post-estimation that I have stored in -local- macros.

    However, given I am using Stata version 14 I cannot use -putdocx- which would solve my problem (indeed I have tried this on a friend's Stata and my code works fine which is most frustrating).

    Instead, I am hoping to achieve my aim using Attaullah Shah great command -asdoc- which allows for exporting a matrix.

    In attempting this I encounter the error: "r(3000): nothing found where subexp expected". I am not sure what to make of this.

    Any help would be much appreciated.

    Code:
    sysuse auto
    
    reg price mpg rep78
    
    local beta1 = _b[mpg]
    local se1 = _se[mpg]
    local beta2 = _b[rep78]
    local se2 = _se[rep78]
    local lower1 = `beta1' - invttail(e(df_r), 0.025)*`se1'
    local upper1 = `beta1' + invttail(e(df_r), 0.025)*`se1'
    local lower2 = `beta2' - invttail(e(df_r), 0.025)*`se2'
    local upper2 = `beta2' + invttail(e(df_r), 0.025)*`se2'
    
    matrix stats = (`beta1', `se1', `lower1', `upper1' \ `beta2', `se2', `lower2', `upper2' )
    
    matrix colnames stats = "Beta" "SE" "Lower 95% Confidence interval" "Upper 95% Confidence interval"
    matrix rownames stats = "Miles per gallon" "Repair record"
    
    asdoc wmat, mat(stats) replace

    Many thanks,
    Alexander
    (Stata v14.2 IC for Mac)

  • #2
    The problem was caused by the matrix row and column names. I have fixed that. The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.
    Code:
    net install asdoc, from(http://fintechprofessor.com) replace
    Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

    The output looks like this
    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	18.2 KB
ID:	1515713

    If you do not have other plans for this lengthy code, then please note that the asdoc's detailed regression table output exactly this table. See this example.
    You can actually customize the detailed regression table by suppressing stars or confidence intervals, see more details here.

    Code:
    asdoc reg price mpg rep78, replace nostars
    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	37.7 KB
ID:	1515714

    Please do remember to cite asdoc. To cite:
    In-text citation
    Tables were created using asdoc, a Stata program written by Shah (2018).

    Bibliography
    Shah, A. (2018). ASDOC: Stata module to create high-quality tables in MS Word from Stata output. Statistical Software Components S458466, Boston College Department of Economics.
    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
      Dear Attaullah Shah
      Thank you for providing such a swift response.

      I can happily confirm the error no longer occurs. Thank you again.

      As we say here in Australia, you're a deadset legend mate!
      Many thanks,
      Alexander
      (Stata v14.2 IC for Mac)

      Comment


      • #4
        Dear Attaullah Shah
        I might just ask as well, any way to limit the decimal places in the output or because I have these data stored in local macros it has to be specified there?
        Thanks again,
        Alexander






        Many thanks,
        Alexander
        (Stata v14.2 IC for Mac)

        Comment


        • #5
          Thanks for the kind words. Yes, you can use the dec() option.

          Code:
          * Using two decimal places
           asdoc wmat, mat(stats) dec(2) replace  
          
          * Using 4 decimal places    
           asdoc wmat, mat(stats) dec(4) replace
          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
            Dear Attaullah Shah
            Thanks again! It worked a treat. The sunnies suit you.

            Many thanks,
            Alexander
            Many thanks,
            Alexander
            (Stata v14.2 IC for Mac)

            Comment


            • #7
              Dear Attaullah Shah here is my code, but I am not getting the exact table in word, please suggest to me.
              use http://fmwww.bc.edu/RePEc/bocode/o/oaxaca.dta, clear
              gen wage=exp(lnwage)
              oaxaca_rif lnwage educ exper tenure, by(female) wgt(1) rif(q(50)) rwlogit(educ exper tenure)
              est sto m1
              oaxaca_rif lnwage educ exper tenure, by(female) wgt(1) rif(q(60)) rwlogit(educ exper tenure)
              est sto m2
              asdoc esttab m1 m2, nogaps se star(* 0.1 ** 0.05 *** 0.01) dec(2) replace

              Comment


              • #8
                Hello everyone,

                I have an issue with the updated version Attaullah provided.
                Before the rownames of my summary statistics were correctly placed but now asdoc eats away one column, please see here: Tables.doc
                Can I do something for this?



                Comment


                • #9
                  SIDITA HASA Can you please post the asdoc code that you used. Perhaps, you are using the sum command with detail option. But that works fine. The current version of asdoc is
                  Code:
                  *! Version 2.3.9.1 : Changes made on Nov 3, 2020

                  The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.
                  Code:
                  net install asdoc, from(http://fintechprofessor.com) replace
                  which asdoc
                  sysuse auto, clear
                  ​​​​​​​asdoc sum, detail
                  Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

                  asdocx is now available
                  A more powerful and flexible version of asdoc is now available. I call it asdocx. You may like to check the details here

                  https://fintechprofessor.com/asdocx


                  Please do remember to cite asdoc. To cite:

                  In-text citation
                  Tables were created using asdoc, a Stata program written by Shah (2018).

                  Bibliography
                  Shah, A. (2018). ASDOC: Stata module to create high-quality tables in MS Word from Stata output. Statistical Software Components S458466, Boston College Department of Economics.

                  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


                  • #10
                    Dear Attaullah,

                    Thank you for your message a while ago! Now it works fine.
                    I have another problem with exporting summary stats and regressions. Stata is rounding all numbers so there are no decimals points while in my code I specify the decimals I want, please see below:

                    Code:
                    asdoc sum cash bonds stocks re alt mortg invemp mxinv, stat(N mean sd p5 p25 p50 p75 p95) tzok dec(2) title(Table 2, Panel A: Summary statistics of asset allocation) font(Times New Roman) append label

                    Result: Tables 1,2,3.doc

                    What's the problem?

                    Thank you in advance!

                    Comment


                    • #11
                      Attaullah Shah Forgot to mention you in the previous message, please see above!

                      Comment


                      • #12
                        It is difficult to identify the problem without using a reproducible example. I am not getting the said error when using the auto dataset
                        Code:
                        sysuse auto
                        asdoc sum price mpg rep78 headroom trunk weight length turn displacement , stat(N mean sd p5 p25 p50 p75 p95) tzok dec(2) title(Table 2, Panel A: Summary statistics of asset allocation) font(Times New Roman) append label
                        Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	16.0 KB
ID:	1616726
                        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


                        • #13
                          Thank you for you message Attaullah Shah!
                          Using your example, I get again a table with rounded numbers, no decimals.. I updated the package and restarted Stata but I have still the same problem!

                          Comment


                          • #14
                            The latest version is
                            Code:
                            which asdoc
                            *!-------------------------------------------------------------------------------
                            *! Version 2.3.9.5 : Changes made on April 10 , 2021 :
                            * Bug fixed in sum command when a variable had all empty values
                            *!-------------------------------------------------------------------------------

                            If you do not have this version, try it from my site
                            The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.
                            Code:
                            net install asdoc, from(http://fintechprofessor.com) replace
                            Please note that the above line has to be copied in full. After installation of the new version, then restart Stata.

                            asdocx is now available
                            A more powerful and flexible version of asdoc is now available. I call it asdocx. You may like to check the details here

                            https://fintechprofessor.com/asdocx


                            Please do remember to cite asdoc. To cite:

                            In-text citation
                            Tables were created using asdoc, a Stata program written by Shah (2018).

                            Bibliography
                            Shah, A. (2018). ASDOC: Stata module to create high-quality tables in MS Word from Stata output. Statistical Software Components S458466, Boston College Department of Economics.


                            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


                            • #15
                              Attaullah Shah Even after the updates, I had the same problem.. What I did and seemed to work is that I opened another Stata window, called the auto data in the system, applied asdoc, saw that I finally had decimals, opened my do file in the same Stata window and ran my code! But I still don't know where this problem comes from and I need to know to avoid it later on, any ideas?

                              Comment

                              Working...
                              X