Presentation is loading. Please wait.

Presentation is loading. Please wait.

Outline for today 1. Advice for your literature review (due next Monday) 2. Announcement about Cleveland International Film Festival next week and an optional.

Similar presentations


Presentation on theme: "Outline for today 1. Advice for your literature review (due next Monday) 2. Announcement about Cleveland International Film Festival next week and an optional."— Presentation transcript:

1 Outline for today 1. Advice for your literature review (due next Monday) 2. Announcement about Cleveland International Film Festival next week and an optional field trip! 3. Introduction to basic programming in Stata 4. If time allows, start an exercise that’s part of this week’s HW 7.

2 Phase 2: Literature review
You are asked to find at least two academic papers that use regression analysis and are relevant to your final paper. They don’t have to be on the same topic. E.g. Suppose you want to study whether more fouls are called against the away team than against the home team in British Premier League soccer games. What’s the core behavior being studied? Judgments by an authority figure who is supposed to be impartial, and whether those judgments respond to “pressure” from spectators. Relevant topics could include: Studies about the home-court advantage more generally (Teams are more likely to win sports games when they play at home.) Other studies of referee impartiality/bias in sports settings. Studies of how authorities in other settings (judges in the courtroom, police officers, teachers) are susceptible to bias and favoritism

3 Next Monday: You are invited to attend a documentary screening at Cleveland International Film Festival. There will be an extra credit opportunity available. We will walk to the RTA together after the lab session. The movie starts at 6:20pm at Tower City Cinema downtown. Tickets cost $3 (special group rate)

4 Hidden things, loops, making tables
Stata Lab Session #9 Hidden things, loops, making tables

5 Basic programming Retrieving values returned by a command
Macros – like temporary “nicknames” Writing loops- useful when you need to perform the same operation on a list of variables, or for several values, one at a time. Posting results to a table or file

6 Background on mumuadu dataset
We will use data from “Crop Indemnified Loans for Farmers: A Pilot Experiment in Rural Ghana,” by Dean Karlan, Ed Kutsoati, Margaret McMillan, and Chris Udry, Journal of Risk and Insurance, forthcoming. Farmers might not take out a loan due to price risk: inability to repay the loan if output prices turn out to be really low Treatment: price-indemnified loan. Don’t have to repay if price at harvest < $x. Control: loan, not indemnified.

7 Commands return (hidden) values
Many commands in Stata produce a number of scalar- and matrix-valued statistics that remain hidden from the display output To see these values, or return list ereturn list help <command> (and scroll down.. summarize age return list display “The variance of age is ” r(Var) summarize age, detail display “The 75th percentile of age is “ r(p75)

8 macros: global and local
Macros store numeric or string sequences in memory global macros last for the entire Stata session. global macros called by $macroname; these stick around until you manually clear them, or you close Stata local macros called by `macroname’; these are only stored locally, i.e. in the context of executing some lines of code in which they are defined Difference in mean revenues for treatment versus control Another example using many “if” statements Using local: Using global: summarize revenuetot if treatment==1 local rev_treat = r(mean) summarize revenuetot if treatment==0 local rev_control = r(mean) display `rev_treat’ - `rev_control’ summarize revenuetot if treatment==1 global rev_treat = r(mean) summarize revenuetot if treatment==0 global rev_control = r(mean) [.. Go off and get tea, run other stuff..] Display $rev_treat - $rev_control global iff if loan==1 summarize revenuetot $iff kdensity revenuetot $iff

9 Loops We want to examine t-tests for many variables
Other looping procedures: forvalues, while Ensure a .log file is open if you want to see output that won’t fit on screen local varsTtest age female dependents educlevel cogsc ambiguity healthins foreach var of local varTtest { ttest `var’, by(treatment) } forvalues j=1/7 { summarize age if cogscore==`j’ } local i = 1 while `i’<=7 { summarize age if cogscore==`i’ local i = `i’ + 1

10 Posting results to a table or file
Say our goal is to run a bunch of t-tests on different variables, looking for differences in treatment versus control, and we want to put all the results in a table (Recall, the mumuadu dataset comes from a study in which farmers were randomized into a control and treatment group. In these types of experiments, even though assignment was random, it is useful to check with a t-test that relevant characteristics look similar between the two groups.) There are many different ways to do this; many of them are user written commands: estout/esttab, sutex, est2tex, outreg2, post (esttab and outreg2 are probably the most popular for writing out regression output)

11 Post results to a table or file
We are going to use post, which writes out a table in the form of a Stata dataset. First we define what the columns of the table are going to be. Then we “post” rows to the table, one-by-one, until we are done, and close the file. Finally, we can bring up this new dataset, admire it, and export if we wish

12 Using post Step 1: create file to post to, specifying variable names
Step 2: run command(s) whose results you want to save, and use post to write out the results Step 3: close postfile postfile <reference-name> <var names> using <file-on-disk-name> e.g.: postfile tests str30 varname meanC meanT diff pval /// using ttest_table, replace qui summarize revenuetot if treatment==1 local rev_T = r(mean) qui summarize revenuetot if treatment==0 local rev_C = r(mean) local diff = `rev_T’ - `rev_C’ ttest revenuetot, by(treatment) post tests (“revenuetot”) (`rev_C’) (`rev_T’) (`diff’) (`r(p)’) postclose tests

13 Using post See how we did: Write it out as .csv use ttest_table, clear
br outsheet using ttest_table.csv, comma replace

14 Exercise #2 An extension of what we just did:
Make a table that compares and t-tests means in treatment group versus control group, for a set of variables: revenuetot quantmaizec soldmarkettrader chemcost_primary Write a loop Post results to a file (let’s call this “exercise2_results”) Write to .csv

15 Exercise #2 - results Hopefully exercise2_results.dta looks something like this: Do check out outreg2 and esttab; these do a lot of things nicely, particularly for regression output…


Download ppt "Outline for today 1. Advice for your literature review (due next Monday) 2. Announcement about Cleveland International Film Festival next week and an optional."

Similar presentations


Ads by Google