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

  • Creating and displaying graphs in a loop with dyndoc


    I try to generate standard graphs with every numeric variable in my dataset and create a nice looking data report with dyndoc. I am not figuring out if creating graphs in a loop with dyndoc let me insert these graphs (Stata 15). My code looks currently like:

    <<dd_version: 1>>
    # Distribution of Variables in data set
    <<dd_do: quietly>>
    set more off
    global p_data "...\2019_Datensaetze\"
    global p_graphs "...\201910_Betriebspanel_Datencheck\graphs\"
    use myfile_ext.dta
    foreach x of varlist * {
     confirm numeric variable `x'
     if !_rc {
      capture drop unique
      egen unique = group(`x')
      quietly: summarize unique
      if `r(max)' < 10{
       di "Variable: `x'"
       graph bar , over(`x') blabel(bar, format(%4.1f)) intensity(25) ///
       ytitle("in Prozent (`x')", size(small))
       graph save "$p_graphs\g_`x'.gph", replace
      * NOT WORKING:
      * <<dd_graph: sav("g_`x'.svg") alt("scatter mpg weight") replace height(400)>>
    <<dd_graph: sav("g_`x'.svg") alt("scatter mpg weight") replace height(400)>>
    only works outside dd_do and cannot be included in the loop....

    What I have tried so far:
    • saving Graphs in loop and using them later - is not working
    • Looping the dyndoc.txt file itselve. That works but creates instead of one html several html files and "append" is not working with dyndoc
    • use putdocx instaed: that works actually, but putdocx gives me trouble with other output I want to create. I prefer very much dyndoc….
    Any suggestions? Is it a question of the stata version maybe and already solved in stata 16?

    Thankyou very much in advance,

    Last edited by Marieke Volkert; 18 Dec 2019, 11:43.