Announcement

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

  • loop for putpdf function

    My goal is to create several PDF reports using the putpdf function. With the data I have right now, I need 1921 reports with the same inputs but each of the 1921 reports will have different values. I have previously used Microsoft Access to generate such reports, but I am looking for a faster/smarter way using Stata. I'm not sure if that's something I can even do though. Is there a way to loop the putpdf function so I create all 1921 reports at once, and they each have their individual data displayed? Also, is there a feature to export and save each report individually and can I use a loop for that too?

    I hope I explained that sufficiently! All help and/or alternate ideas would be greatly appreciated.

  • #2
    Hi! Did you discover how to do it? I have to do the same. Thanks!

    Comment


    • #3
      I would make two .do files: one that makes the report for a specific subsample, dataset, group, whatever, lets call that one make_report.do. The second .do file loops over the groups and calls the make_report.do file. The trick is that you can pass arguments to a do-file. So if you type do make_report.do foo, then at the very beginning of running make_report.do the local macro `1' will be defined and it will contain "foo". You can easily give the macros more meaningful names using the args command. If you type args bar then instead of `1' being "foo" it will be `bar' being "foo".

      Here is a silly example of what a make_report.do file could look like:
      Code:
      version 17
      args sample
      
      putpdf begin , pagesize(A4)
      putpdf paragraph , halign(center)
      local industry : label (industry) `sample'
      putpdf text ("summary for `industry'"), bold font(" ", 16)
      
      putpdf paragraph, halign(left)
      sum wage if industry == `sample'
      putpdf text ("The mean wage for women working in `industry' is ")
      putpdf text (`r(mean)'), nformat(%4.1g)
      putpdf text (" dollars per hour.")
      
      
      putpdf save report`sample'.pdf, replace
      Here is the do-file that calls make_report.do

      Code:
      sysuse nlsw88, clear
      cd c:\temp
      
      levelsof industry
      local levs = r(levels)
      foreach lev of local levs {
          do make_report.do `lev'
      }
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment

      Working...
      X