![]() Combining dozens or hundreds of graphs into a single video with a program is faster and easier than using a drag-and-drop interface. This means that we can create our graphs and combine them into a video using Stata do files. ![]() Second, FFmpeg can be called from within the Stata environment using the winexec command. First, the software is readily available and free. Robert followed the same basic strategy I demonstrated above, but Robert’s choice of software has two appealing features. In his presentation, Robert demonstrated how to combine graph images into a video using a free software program called FFmpeg. You can read more about Robert by visiting his blog and clicking on About. Stata user and medical statistician Robert Grant gave a presentation at the 2012 UK Stata User Group Meeting in London entitled “ Producing animated graphs from Stata without having to learn any specialized software“. We just created our first animated graph! All we have to do to make it look as professional as the power-and-sample size examples I showed you earlier is go back into our Stata program and modify the graph command to add the additional elements we want to display! Creating videos with FFmpeg I’ve exported to a “.gif” file because it is easy to view in a web browser. Next we drag the images onto the timeline:Īnd then we make the display time for each image very short…in this case 0.1 seconds or 10 frames per second.Īfter previewing the video, we can export it to any of Camtasia’s supported formats. We begin by importing the graph files into Camtasia: Camtasia is a commercial video program that I use to record videos for the Stata Youtube channel and its interface looks like this. The user imports image, sound and video files, organizes them in tracks on a timeline and then previews the resulting video. Most commercial video editing programs have similar interfaces. I will outline the basic steps using two of them, one a commerical GUI based product (not free) called Camtasia, and the other a free command-based program called FFmpeg. There are many commercial, freeware, and free software programs available that we could use. Now that we have created our graphs, we need to combine them into a video. We can view the contents of the directory to verify that Stata has created a file for each of our graphs. Note that the name of each graph file includes the value of mu so that we know the order of our files. Graph export graph_`mu'.png, as(png) width(1280) height(720) replace We can do this by adding graph export inside the loop. We can fix that by reformating the means using the string() function. That’s not a mistake, it’s because Stata stores numbers and performs calculations in base two and displays them in base ten for a detailed explanation, see Precision (yet again), Part I. You may have also noticed that some of the values of the mean did not look as you would have wanted. You may have noticed the illusion of motion as Stata created each graph the normal densities appeared to be moving to the right as each new graph appeared on the screen. The loop below creates a series of graphs of normal densities with means 0 through 1 in increments of 0.1. If, for each interation, the graph command created a slightly different graph, we would be on our way to creating our first video. We could place a graph command inside the loop. If you are not familiar with loops in Stata, here’s one to count to five: To create the illusion of motion with graphs, we make an ordered series of slightly differing graphs. Our brains perceive this series of still images as motion. All videos - from Charles-Émile Reynaud’s 1877 praxinoscope to modern blu-ray movies - are created by displaying a series of ordered still images for a fraction of a second each. Creating animated graphs allowed me to skip the explanation and just show what I meant. Both of these concepts can be illustrated with a static graph along with the explanation “imagine that …”. I wanted to illustrate two concepts: (1) that statistcal power increases as sample size increases, and (2) as effect size increases. I recently recorded a video for the Stata Youtube channel called “ Power and sample size calculations in Stata: A conceptual introduction“. I will show you how I create my animated graphs using Camtasia and how Robert creates his using FFmpeg. At the 2012 UK Stata User Group Meeting Robert Grant demonstrated how to create animated graphics from within Stata using a free software program called FFmpeg. In addition to Stata, you will need a video editing program but don’t be concerned if you don’t have one. It’s easier than you might expect and you can use animated graphics to illustrate concepts that would be challenging to illustrate with static graphs. Today I want to show you how to create animated graphics using Stata.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |