Announcement

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

  • greating animated graphs as per robert grant

    Hi I've been trying to create an animated graph using Robert Grant resources from here

    First youtube video available here:
    http://www.robertgrantstats.co.uk/an...aphs/line.html

    Do file available here;
    http://www.robertgrantstats.co.uk/an...illing_line.do


    I've tried working around it, but using P Lambert dataset (as R Grant doesn't provide a dataset - so had to make do with stuff available)
    The problem is nothing happens at the end... I just end up with - end do file-

    I'm not sure if it's because I get the following message - but it doesn't appear as an error in red

    zsh:1: command not found: del

    Click image for larger version

Name:	Screenshot 2023-11-08 at 21.46.25.png
Views:	1
Size:	121.8 KB
ID:	1733232

    Here's my code:

    Code:
    
    
    stset rf, f(rfi==1) scale(12) exit(time 60)
    
    use https://www.pclambert.net/data/rott2b
    
    //Use here Predict survival as a function of age
    gen t5=5 
    predict t5_age, surv at(hormon 0 pr_1 3.43) ci timevar(t5)
    
    //Robert grant code begins from here 
    
    local frames 100 // in this simple example there is one frame per time point
    #delimit ;
    local opts "legend(off) graphregion(color(white)) 
                ylabel(0(0.5)1.0) yscale(range(0 1.0))
                xlabel(0(20)100) xscale(range(0 100))";
    #delimit cr
    
    twoway (rarea t5_age_uci t5_age_lci age if age<1, lcolor(gs14) fcolor(gs14)) ///
           (line t5_age age if age<1), ///
           `opts' title("Age = 0") name(line0, replace)
    graph export "`picpath'line0.png", replace
    
    // loop over frames
    forvalues i=1/`frames' {
        twoway (rarea t5_age_uci t5_age_lci age if age<=`i', lcolor(gs14) fcolor(gs14)) ///
               (line t5_age age if age<=`i'), ///
               `opts' title("Age = `i'") name(line`i', replace)
        graph export "`picpath'line`i'.png", replace
        graph drop line`i' // to stop the Graph Window being cluttered
    }
    
    
    // make the video
    !del "`vidpath'filling_line.mpg" // overwrite existing file
    sleep 500 // make sure the file has been deleted before proceeding
    winexec "/Users/martinaib/Downloads/ffmpeg-6.0.tar.xz" /// or wherever you have saved it
        -report -i "`picpath'line%d.png" -b:v 2048k ///
        "`vidpath'filling_line.mpg"
    In addition my graphs, look like this (see below - greyish rough sketched area )
    rather than the beautiful smoothly shaded blue parts and red line in the curves provided by https://pclambert.net/statasvg/stpm2..._age_time5.png

    Of course I never get to view the video.....so not sure if with the ffmpeg, this issue is solved...

    Also, do you think its impossible to overlay another plot for hormone = 1 as well... not sure if stata can cope....

    It would have:
    [CODE
    predict t5_age2, surv at(hormon 1 pr_1 3.43) ci timevar(t5)
    [/CODE}

    Click image for larger version

Name:	capture1.jpg
Views:	1
Size:	154.3 KB
ID:	1733233



  • #2
    The !del is a shell command and its purpose here seems to be to delete the file before writing a new one. Could you use Stata's erase to do this?
    Code:
     
     erase "`vidpath'filling_line.mpg"

    Comment


    • #3
      Thanks, answers to my post
      1. Yes can overlay 2 graphs
      2. One needs to sort the data to prevent the image in post1 and obtain the image present in P Lamberts
      3. Replace !del with !rm --> advice from the author himself

      Comment

      Working...
      X