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. The text option just allows me to place text at a given location.Today I want to show you how to create animated graphics using Stata. This prevents me from having _N (total number of observations in the data set) dots all right on top of each other, which will use up more resources. The restriction if _n=1 tells stata to only use observation number one. What I did was create the average price and mpg as varabiles, then drew my primary scatter plot and then overlaid a single dot. (scatter avgmpg price if _n=1, mcolor(red) legend(off) /// I came up with the following work around: You can put a line using xline and yline options (see below). I recently had the need to put a single dot of a different color on a graph, and noted that stata doesn't have an option to allow you to place a single dot on a graph.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |