Producing animated graphs from Stata without having to learn any other software Robert Grant Senior...
-
Upload
tia-caufield -
Category
Documents
-
view
216 -
download
0
Transcript of Producing animated graphs from Stata without having to learn any other software Robert Grant Senior...
![Page 1: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/1.jpg)
Producing animated graphs from Stata without having to learn
any other software
Robert GrantSenior Research Fellow
St George’s, University of London& Kingston University
![Page 2: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/2.jpg)
www.animatedgraphs.co.uk 2
The objective
I have seen some cool graphs made into videos like Hans Rosling’s 200 Countries
and I thought “I want to do that!”Stata Users’ Group London 2012
![Page 3: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/3.jpg)
www.animatedgraphs.co.uk 3
The objective
• I analyse data all day long• I am (if I say so myself) pretty good using stats software• but I know nothing about video software• and in fact I don't have the time/money/energy to learn
Stata Users’ Group London 2012
![Page 4: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/4.jpg)
www.animatedgraphs.co.uk 4
The objective
• I analyse data all day long• I am (if I say so myself) pretty good using stats software• but I know nothing about video software• and in fact I don't have the time/money/energy to learn
• I want to make animations from inside Stata • I want the process to be simple but totally
flexible so I am not restricted in the look of my animations and the effects I can build into them.
Stata Users’ Group London 2012
![Page 5: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/5.jpg)
www.animatedgraphs.co.uk 5
Stop frame animation
• Movies are made up of a series of still images• If you can control the images, you can make anything
happen• You already know how to control Stata graphs
Stata Users’ Group London 2012
![Page 6: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/6.jpg)
www.animatedgraphs.co.uk 6
Stop frame animation
For Ray Harryhausen or Nick Park and their talented animators, this was (and still is) very hard work
Stata Users’ Group London 2012
But you have Stata programming at your disposal to make lots of images quickly
![Page 7: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/7.jpg)
www.animatedgraphs.co.uk 7
The basic do-file
• Set up macros with the graph options• Loop over the number of frames
• Advance / interpolate the data one step• Draw the graph• Export the graph
• Use -winexec- to call the free open source software FFMPEG and make the images into a video file
• FFMPEG runs “behind the scenes” (no GUI)
Stata Users’ Group London 2012
![Page 8: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/8.jpg)
www.animatedgraphs.co.uk 8
Example 1: Line filling from left to right
Stata Users’ Group London 2012
![Page 9: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/9.jpg)
www.animatedgraphs.co.uk 9
Example 1: Line filling from left to right
Stata Users’ Group London 2012
![Page 10: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/10.jpg)
www.animatedgraphs.co.uk 10
Example 2: Line scrolling from left to right
Stata Users’ Group London 2012
![Page 11: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/11.jpg)
www.animatedgraphs.co.uk 11
Example 3: Interpolated scatterplot
Stata Users’ Group London 2012
![Page 12: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/12.jpg)
www.animatedgraphs.co.uk 12
Example 4: Trails made with phantom data
Stata Users’ Group London 2012
![Page 13: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/13.jpg)
www.animatedgraphs.co.uk 13
Use or abuse?
• It is possible to draw the eye to one aspect of the animation through your aesthetic choices
• “My voice is a powerful gift. It can be used for good or it can be used for evil.” - Barry White
• Some points might move faster than others; should data start and stop moving together?
• Be careful to control axes so they don’t creep• Colour, light, emphasis, sound
Stata Users’ Group London 2012
![Page 14: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/14.jpg)
www.animatedgraphs.co.uk 14
Example 5: Hans recreated
Stata Users’ Group London 2012
![Page 15: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/15.jpg)
www.animatedgraphs.co.uk 15
Stata strengths and weaknesses
The ease and flexibility of macrosHaving a direct link to the operating systemPowerful graphicsXHaving to display each graph slows it downXHaving to split into multiple -graph twoway- commands to change size and colour
Stata Users’ Group London 2012
![Page 16: Producing animated graphs from Stata without having to learn any other software Robert Grant Senior Research Fellow St Georges, University of London &](https://reader036.fdocuments.net/reader036/viewer/2022062511/551643b7550346b2068b542f/html5/thumbnails/16.jpg)
www.animatedgraphs.co.uk 16
www.animatedgraphs.co.uk
• All these examples, and some more• All the do-files• Tips on achieving particular aesthetics• User contributions• Expanding into R, SPSS, and maybe Excel VBA• Consultancy: I can do bespoke graphs but
would rather teach you how to catch the fish
Stata Users’ Group London 2012