Applied Microeconometrics - Introduction to stata 2 ... · Applied Microeconometrics Introduction...
Transcript of Applied Microeconometrics - Introduction to stata 2 ... · Applied Microeconometrics Introduction...
Applied MicroeconometricsIntroduction to stata 2: Beyond variables
Loops, macros, scalars (& graphs if we have time)
Alessandro Martinello
alfa 4035B
AM’s reminders
Mail policyNO content questions by emailAsk during/between classes or just walk over to α 4035B
1 / 9
Last time
What is stata
Opening dataset (use [using] [if])
VariablesCreating and replacing (gen, gen, replace)Data selection (booleans, [if])Descriptive statistics (tabulate, table, summarize [, detail])Variable types and labels
2 / 9
Other data in stata
MacrosGlobals, localsLoops
ResultsAccessing and storing them
Scalars (and matrices)
If time, graphs
3 / 9
Macros as strings
Store and repeat text
Globals: e.g. global variables age female ln wageLasts all session, across files (clear all)Access as $variables
Locals: e.g. local variables age female ln wageLasts only while command (do-file) is executedAccess as ‘variables’ (grave accent - apostrophe)Invoked in loops
4 / 9
Working with macros
Loops
foreach name in/of, forval name = numlistCommands between braces repeated‘name’ accessed as localSee also while (and if)
In regressionsOLS: reg depvar indepvar(s) [if] [, options ]
depvar indepvars can be macros/varlistInteraction syntax: i.discrete, c.continuous, #, ##Shortcuts for varlist: *, ?
5 / 9
Acccessing results
Saved resultsIn e()/r(), see command help fileEstimation results: b[varname], se[varname]Save them as macros, scalars or matrix
6 / 9
Graphs - examples: connectedFiscal revenue over GDP of selected countries over time
2030
4050
% o
f GD
P
1960 1970 1980 1990 2000 2010Year
Sweden Italy USGreece Germany Denmark
7 / 9
Graphs - examples: scatterParticipation in financial markets over intelligence, DK
.1.2
.3.4
60 80 100 120 140BPP score (IQ scale)
<7th grade 8th grade or more Tertiary educ.
7 / 9
Graphs - examples: kdensityCorrelation between intelligence and schooling, DK
0.0
1.0
2.0
3
60 80 100 120 140 160BPP score (IQ scale)
<7th grade 8th grade or more Tertiary educ.
7 / 9
Stata - graphing machine
help graphhelp twoway: combined with data management tools can doalmost anything
graph export mydir/mygraph.myformat, replace
Stata defaults are ugly - but can be easily changed
GUI interface / script (do-files)Repeatability (loops)
8 / 9
Plotting demographic evolutions
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
-10 -5 0 5 10Population in millions
Males Females
Population by Age, Japan 1950
9 / 9
Plotting demographic evolutions
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
-10 -5 0 5 10Population in millions
Males Females
Population by Age, Japan 1970
9 / 9
Plotting demographic evolutions
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
-10 -5 0 5 10Population in millions
Males Females
Population by Age, Japan 1990
9 / 9
Plotting demographic evolutions
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
-10 -5 0 5 10Population in millions
Males Females
Population by Age, Japan 2010
9 / 9
Plotting demographic evolutions
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
-10 -5 0 5 10Population in millions
Males Females
Population by Age, Japan 2030
9 / 9
Plotting demographic evolutions
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
00-0405-0910-1415-1920-2425-2930-3435-3940-4445-4950-5455-5960-6465-6970-7475-7980-8485+
-10 -5 0 5 10Population in millions
Males Females
Population by Age, Japan 2050
9 / 9