Creating PowerPoint Presentations in Stata with Slide Deck

Slide Note
Embed
Share

"Discover how to generate PowerPoint presentations directly from Stata using Slide Deck, a suite of programs leveraging Python integration. Learn about the prerequisites, how it works, and key terminology. Follow a sample session to load economic data and save graphs for effective presentation."


Uploaded on Jul 20, 2024 | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Slide Deck: PowerPoint Presentations within Stata Stata Conference 2022 Tim Schmidt Treasurer Discover Financial Services August 4 Washington, DC

  2. Introducing Slide Deck Slide Deck is a suite of Stata programs in two Stata classes: slide.class deck.class Facilitates the creation of PowerPoint presentations from within a Stata session Takes advantage of Stata 17 s Python integration Builds upon python-pptx Python library for creating and updating PowerPoint files https://pypi.org/project/python-pptx/ https://github.com/scanny/python-pptx 2

  3. Prerequisites: What You Need Python version 3 https://python.org/downloads/ Python-pptx Python library pip install python-pptx slidedeck Python library Included as source code in this project Place it in your Python path Stata version 17 Integrates Python 3

  4. How It Works Office 2007 and later versions use Open XML file formats (.pptx) python-pptx library offers methods to create/edit .pptx format files My slidedeck Python library simplifies use of python-pptx slideand deck Stata classes encapsulate data for slide and deck constructs and programs to interact with slidedeck (directly) and python-pptx (indirectly) To create a PowerPoint presentation: Instantiate a deck using deck class Instantiate one or more slides using slide class Add slides to the deck and save it 4

  5. Terminology & Concepts Title deck objects contain slide objects Margin bullets deck object must contain at least one Layout a slide template Main bullets slide objects encapsulate data for the slide components (e.g., title, exhibits, etc.) and methods (programs) to act on the data Title Use Markdown-style formatting in main and margin bullets deck renders slides when user saves the deck Deck becomes a PowerPoint presentation when user saves it as .pptx file Margin bullets Exhibits Footnotes 5

  6. Sample Session (1:6) * Load and label monthly economic data insheet using econmo.csv, comma clear drop date gen date = mofd(mdy(month, day, year)) format %tmMonYY date order date sort date lab var icpiu "CPI-U index, 1982-84=100, sa" lab var iip "Industrial production index, 2017=100, sa" lab var ru3 "U-3 unemployment rate, pct, sa" Saving Stata graphs in PNG format (JPEG works too) * Create time series graphs line ru3 date, xtitle("") title("Unemployment Rate") graph export ru3.png, replace line iip date, xtitle("") title("Industrial Production") graph export iip.png, replace 6

  7. Sample Session (2:6) * Create inflation variable and graph it gen pcpiu = ((icpiu/icpiu[_n-12])-1)*100 lab var pcpiu "CPI-U inflation, pct, YoY" line pcpiu date, xtitle("") title("CPI-U Inflation") graph export pcpiu.png, replace save econmo, replace * Load and label quarterly economic data insheet using rgdp.csv, comma clear drop date gen date = qofd(mdy(month, day, year)) format %tqYY:q date order date sort date lab var rgdp "Real GDP, 2012 dollars, sa" 7

  8. Sample Session (3:6) * Create real GDP growth variable and graph it gen rrgdp = ((rgdp/rgdp[_n-4])-1)*100 lab var rrgdp "Real GDP growth, pct, sa" line rrgdp date, xtitle("") title("Real GDP Growth") graph export rrgdp.png, replace save econqtr, replace * Create a new deck object .d = .deck.new "dfsslides.pptx" Creating a new deck instance 8

  9. Sample Session (4:6) * Create a four-graph slide and add it to the deck object Creating new slide instance Adding title, graphs ( exhibits ) and margin bullets to slide .s1 = .slide.new econoverview .s1.set_title "U.S. Economic Conditions" .s1.add_exhibits rrgdp.png iip.png ru3.png pcpiu.png .s1.add_margin_bullets - Real GDP continues to expand, but growth is slowing .s1.add_margin_bullets - Industrial production has recovered strongly from the pandemic-induced recession .s1.add_margin_bullets - Unemployment remains near its record low given strong labor market conditions .s1.add_margin_bullets - Consumer price inflation has reached a ^ four-decade ^ high Note use of Markdown- style formatting .d.add_slide .s1 Adding slide to deck 9

  10. Sample Session (5:6) * Create an all-text slide and add it to the deck object Note use of Markdown- style formatting .s2 = .slide.new execsummary .s2.set_title "Executive Summary" .s2.add_main_bullets + ^16 U.S. economic expansion continues, but the pace of growth has slowed .s2.add_main_bullets ++ Consensus forecast suggests below-trend growth in second half of 2022 .s2.add_main_bullets + ^16 Labor market conditions remain very strong amid high labor demand and low participation rates .s2.add_main_bullets + ^16 Unusually high inflation will prompt tighter monetary policy from the Federal Reserve .d.add_slide .s2 Formatting syntax: ^ ^^ ^# ^Fontname Bullet syntax: + ++ - Italics Bold Font size Font Main bullet, level 1 Main bullet, level 2 Margin bullet, level 1 10

  11. Sample Session (6:6) * Show the slides in the deck .d.show_slides * Delete a slide from the deck and show that it's gone .d.del_slide .s2 .d.show_slides You may delete slides * Add the slide back, this time to the front of the deck and add them back in a new spot to reorder them .d.add_slide .s2 1 .d.show_slides * Save the deck with the two slides; slides are "rendered" at save .d.save "econreview.pptx" Slides aren t rendered until the deck is saved 11

  12. Executive Summary U.S. economic expansion continues, but the pace of growth has slowed Consensus forecast suggests below-trend growth in second half of 2022 Labor market conditions remain very strong amid high labor demand and low participation rates Unusually high inflation will prompt tighter monetary policy from the Federal Reserve

  13. U.S. Economic Conditions Real GDP continues to expand, but growth is slowing Industrial production has recovered strongly from the pandemic-induced recession Unemployment remains near its record low given strong labor market conditions Consumer price inflation has reached a four- decade high

  14. Future Enhancements Incorporate Stata tables Accommodate more slide components/features Expand Markdown-style formatting options 14

  15. slide Class Documentation slide Function Instantiate new slide slide.class constructor Name new Usage example .s1 = .slide.new execsummary Comment(s) Slides must have a unique, one-word name when created slide.class methods Name set get_name show_name set_title get_title show_title add_exhibits get_exhibits show_exhibits num_exhibits add_main_bullets get_main_bullets show_main_bullets num_main_bullets get_main_runs Function Set slide name Return slide name Display slide name Set slide title Return slide title Display slide title Add exhibit(s) to slide Return string of exhibit filename(s) Display exhibit filename(s) Return number of exhibits Add text bullet(s) to main text area Return string of main bullet(s) text Display main bullet(s) text Return number of main bullets Return string of main bullet "runs" (bullet text surrounded by paragraph level, typeface settings, etc.) Usage example .s1.set execsummary local name "`.s1.get_name'" .s1.show_name .s1.set_title "This is the slide local title "`.s1.get_title'" .s1.show_title .s1.add_exhibits sales.png local exhibits "`.s1.get_exhibits'" .s1.show_exhibits local numex "`.s1.num_exhibits'" .s1.add_main_bullets "+ Point one ++ local mbtext "`.s1.get_main_bullets'" .s1.show_main_bullets local nummb "`.s1.num_main_bullets'" local mr "`.s1.get_main_runs'" Comment(s) Slide name is required at instantiation, so mostly for name changes Markdown-style symbols ("+") indicate bullet "level" (<= 5) Runs are comma-separated; typeface settings are colon-separated quartets of font name, size, bold and italics settings (e.g., Arial:9:True:False) show_main_runs add_margin_bullets get_margin_bullets show_margin_bullets num_margin_bullets get_margin_runs Display main bullet "runs" Add text bullet(s) to margin text area Return string of margin bullet(s) text Display margin bullet(s) text Return number of margin bullets Return string of margin bullet "runs" (bullet text surrounded by paragraph level, typeface settings, etc.) .s1.show_main_runs .s1.add_margin_bullets "- Point one -- Markdown-style symbols ("-") indicate bullet "level" (<= 3) local mbtext "`.s1.get_main_bullets'" .s1.show_margin_bullets local nummb "`.s1.num_margin_bullets'" local mr "`.s1.get_margin_runs'" Runs are comma-separated; typeface settings are colon-separated quartets of font name, size, bold and italics settings (e.g., Arial:9:True:False) show_margin_runs Display margin bullet "runs" Add text to footnote area .s1.show_margin_runs .s1.add_footnotes "* Footnote number one" local fntext "`.s1.get_footnotes'" .s1.show_footnotes .s1.show_footnote_runs local numfn "`.s1.num_footnotes'" add_footnotes get_footnotes show_footnotes show_footnote_runs num_footnotes Markdown-style symbols ("*") indicate footnote "level" Return string of footnote(s) text Display footnote(s) text Display footnote "runs" Return number of footnotes 15

  16. deck Class Documentation deck.class constructor Name new Function Instantiate new PowerPoint deck Usage example .d1 = .deck.new "c:/templates.pptx" Comment(s) .pptx file must contain at least one slide layout deck.class methods Name save Function Save deck as .pptx file Usage example .d1.save "c:/trends.pptx" Comment(s) Will write over file if given existing filename; slides are "rendered" at this time Components added to slide object and to deck, but not yet "rendered" add_slide del_slide show_fn show_slides num_slides show_layouts find_layout Add slide object to deck Delete slide object from deck Display filename specified at instantiation Display name(s) of slide(s) in deck Return number of slides in deck Display components of each slide layout Find which layout(s) accommodate slide features .d1.add_slide .s1 .d1.del_slide execsummary .d1.show_filename .d1.show_slides local numsl "`.d1.num_slides'" .d1.show_layouts .d1.find_layout add_slide uses this method and defaults to the first 16

More Related Content