Announcement

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

  • putdocx command.

    I am having trouble figuring out how to put a twoway tabulate table with putdocx . The output is below


    Click image for larger version

Name:	Screen Shot 2017-06-17 at 8.09.26 AM.png
Views:	2
Size:	136.9 KB
ID:	1398213

    How can i put this table in putdocx command.

    Code:
    sysuse auto.dta
    
    tab make foreign
    Attached Files

  • #2
    As -putdocx- is a brand new command, nobody has a lot of experience with it yet. The output of tabulate does not, as I understand it, directly work with -putdocx-. But -tabulate- has option -matcell()- that allows you to save the table in a matrix. And then you can use that matrix with -putdocx-.

    Comment


    • #3
      Sir can you help me out, by just giving a example for use of matcell, i tried reading the manual but i am not able to figure out. Thank you.

      Comment


      • #4
        Code:
        sysuse auto, clear
        tab make foreign, matcell(M)
        
        putdocx table my_table = matrix(M)
        The code presumes you have already initialized a document with -putdocx begin-. And you may want to customize the appearance of the table using various options available in the -putdocx- command.

        Comment


        • #5
          I, too, was very surprised that the very helpful new -putdocx- command does not come "out of the box with this seemingly basic capability! Needing to do just what your post is about for a project of my own, I concocted this workaround that more or less produces what you are looking for.

          Code:
          sysuse auto
          contract make foreign
          putdocx begin
          putdocx table mytable = data(make foreign _freq), varnames width(50%)
          putdocx save "filepath.docx", replace

          Then, simply go to the location where you saved the .docx and this should be waiting for you:
          make foreign _freq
          AMC Concord Domestic 1
          AMC Pacer Domestic 1
          AMC Spirit Domestic 1
          Audi 5000 Foreign 1
          Audi Fox Foreign 1
          BMW 320i Foreign 1
          Buick Century Domestic 1
          Buick Electra Domestic 1
          Buick LeSabre Domestic 1
          Buick Opel Domestic 1
          Buick Regal Domestic 1
          Buick Riviera Domestic 1
          Buick Skylark Domestic 1
          Cad. Deville Domestic 1
          Cad. Eldorado Domestic 1
          Cad. Seville Domestic 1
          Chev. Chevette Domestic 1
          Chev. Impala Domestic 1
          Chev. Malibu Domestic 1
          Chev. Monte Carlo Domestic 1
          Chev. Monza Domestic 1
          Chev. Nova Domestic 1
          Datsun 200 Foreign 1
          Datsun 210 Foreign 1
          Datsun 510 Foreign 1
          Datsun 810 Foreign 1
          Dodge Colt Domestic 1
          Dodge Diplomat Domestic 1
          Dodge Magnum Domestic 1
          Dodge St. Regis Domestic 1
          Fiat Strada Foreign 1
          Ford Fiesta Domestic 1
          Ford Mustang Domestic 1
          Honda Accord Foreign 1
          Honda Civic Foreign 1
          Linc. Continental Domestic 1
          Linc. Mark V Domestic 1
          Linc. Versailles Domestic 1
          Mazda GLC Foreign 1
          Merc. Bobcat Domestic 1
          Merc. Cougar Domestic 1
          Merc. Marquis Domestic 1
          Merc. Monarch Domestic 1
          Merc. XR-7 Domestic 1
          Merc. Zephyr Domestic 1
          Olds 98 Domestic 1
          Olds Cutl Supr Domestic 1
          Olds Cutlass Domestic 1
          Olds Delta 88 Domestic 1
          Olds Omega Domestic 1
          Olds Starfire Domestic 1
          Olds Toronado Domestic 1
          Peugeot 604 Foreign 1
          Plym. Arrow Domestic 1
          Plym. Champ Domestic 1
          Plym. Horizon Domestic 1
          Plym. Sapporo Domestic 1
          Plym. Volare Domestic 1
          Pont. Catalina Domestic 1
          Pont. Firebird Domestic 1
          Pont. Grand Prix Domestic 1
          Pont. Le Mans Domestic 1
          Pont. Phoenix Domestic 1
          Pont. Sunbird Domestic 1
          Renault Le Car Foreign 1
          Subaru Foreign 1
          Toyota Celica Foreign 1
          Toyota Corolla Foreign 1
          Toyota Corona Foreign 1
          VW Dasher Foreign 1
          VW Diesel Foreign 1
          VW Rabbit Foreign 1
          VW Scirocco Foreign 1
          Volvo 260 Foreign 1


          Best wishes and here's to hoping Stata makes this more straightforward very soon!

          Comment


          • #6
            Code:
             sysuse auto
            contract make foreign
            putdocx begin
            putdocx table mytable = data(make foreign _freq), varnames width(50%)
            putdocx save "filepath.docx", replace

            Comment


            • #7
              I believe I have a potential contribution for this thread. Very preliminary - may need some work. But for me it is working quite well.

              First, save the following code as tbl2putdocx.ado to your working directory.

              Code:
              capture program drop tbl2putdocx
              program tbl2putdocx
                  qui{
                      version 15
                      syntax anything(id="arglist")
                      preserve
                      capture decode `1', gen(dec`1')
                      if _rc {
                          gen dec`1' = `1'
                      }
                      tab dec`1'
                      putdocx table dec`1'_sector = (`r(r)',2)
                      levelsof dec`1', local(row_names)
                      local count = 1
                      qui foreach lev in `row_names' {
                          putdocx table dec`1'_sector(`count',1) = ("`lev'")
                          count if dec`1' == "`lev'"
                          local curcnt = `r(N)'
                          putdocx table dec`1'_sector(`count',2) = ("`curcnt'")
                          local count = `count' + 1
                      }
                      restore
                  }
              end
              Second, the following example produces what I believe is the desired result:

              Code:
              clear all
              sysuse auto
              
              capture putdocx clear
              putdocx begin
              
              putdocx paragraph, style(Title)
              putdocx text ("Here is a demonstration of -tbl2putdocx-")
              
              putdocx paragraph
              putdocx text ("Here is some text for demonstration purposes. Followed by a table:")
              tbl2putdocx foreign
              
              putdocx paragraph
              putdocx text ("Here is some text for demonstration purposes. Followed by a table from a different data set:")
              use http://www.stata-press.com/data/r15/nlswork.dta, clear
              tbl2putdocx race
              
              putdocx paragraph
              putdocx text ("For good measure, one last example. Followed by three tables from a third different data set:")
              sysuse bplong.dta, clear
              tbl2putdocx when
              tbl2putdocx sex
              tbl2putdocx agegrp
              
              putdocx save "StataListDemo.docx", replace
              ~ Adam

              PS: Watch for an update on this in the next few days. I'd be up for any input from collaborators who might like to see this available via net install...

              EDIT: Removed some of the lines I had for debugging purposes. Also added qui prefix for less verbose output.
              Last edited by Adam Ross Nelson; 30 Oct 2017, 20:58.

              Comment


              • #8
                Giving this a bump to let folks know about smrtbl user written package.

                ssc install smrtbl

                available commands are:

                smrtbl
                smrcol
                smrfmn

                Edit: Added list of available commands.

                Comment


                • #9
                  Hi,

                  You can also use the user written asdoc package

                  Code:
                  . ssc instal asdoc
                  And then run this command:
                  Code:
                  . asdoc tab make foreign

                  Comment


                  • #10
                    Thanks for the tip on asdoc. I'm a fan of some of Shah's other packages also.

                    Comment


                    • #11

                      how to add templates with putdocx Can you add newsletter templates? type: https://templates.office.com/es-es/boletín-semanal-tm33875558

                      Comment

                      Working...
                      X