├── README.md ├── data ├── 03_gilens.dta ├── 04_larsen.dta ├── 04_steenbergen.rdata ├── 07_ggl.csv ├── 08_gg.csv └── 1_worldpop.csv ├── index.html ├── javascripts └── scale.fix.js ├── params.json ├── scripts ├── 02_rintro.R ├── 03_reg1.R ├── 04_reg2.R ├── 07_exp1.R ├── 08_exp2.R └── 09_content1.R ├── slides ├── 01_logic1.pdf ├── 02_logic2.pdf ├── 03_regression1.pdf ├── 04_regression2.pdf ├── 07_experiments1.pdf ├── 08_experiments2.pdf ├── 09_contentanalysis1.pdf └── 10_contentanalysis2.pdf └── stylesheets ├── github-light.css └── styles.css /README.md: -------------------------------------------------------------------------------- 1 | ## Logic of Quantitative Research in Political Science 2 | 3 | This repo contains information about and materials for "Logic of Quantitative Research in Political Science", a five-day graduate-level course held at the University of Copenhagen, February 6-10, 2017. The course is taught by postdoc [Frederik Hjorth](http://fghjorth.github.io), associate professor [Asmus Leth Olsen](http://asmusolsen.com), and associate professor [Jacob Gerner Hariri](http://politicalscience.ku.dk/staff/academic_staff/?pure=en/persons/196635). 4 | 5 | ### Description 6 | 7 | The course will use illustrative examples from the political science literature, and emphasizes the logic of research designs rather than their implementation in statistical software. The course equips students with concepts needed to understand the reasoning behind research designs and modeling in quantitative political science research. 8 | 9 | The course is structured around five themes, one covered each day: 10 | 11 | 1. Logic of quantitative research 12 | - Regression 13 | - Natural Experiments 14 | - Experiments 15 | - Content analysis 16 | 17 | The course covers the key methodological approaches within each theme as well as canonical research articles applying the relevant approach. For more details, see [Course schedule](#course-schedule) below. 18 | 19 | Students will also have the opportunity to present and receive feedback on their own ongoing work (see [Research paper](#research-paper) below). 20 | 21 | ### Signing up 22 | 23 | To sign up for the course, please send an email to [phdcourses@ifs.ku.dk](mailto:phdcourses@ifs.ku.dk). 24 | 25 | ### Course schedule 26 | 27 | Block | Day | Time | Theme | Instructor 28 | ---|---|---|---|--- | 29 | 1 | Monday | 9-12 | Logic 1: Quantitative research designs | Frederik Hjorth 30 | 2 | | 13-16| Logic 2: Controversies about the quantitative approach | Frederik Hjorth 31 | 3 | Tuesday | 9-12 | Regression 1: Linear regression | Frederik Hjorth 32 | 4 | | 13-16| Regression 2: Panel data and interaction models | Frederik Hjorth 33 | 5 | Wednesday | 9-12 | Natural experiments 1: IV, difference-in-difference | Jacob Gerner Hariri 34 | 6 | | 13-16| Natural experiments 2: Natural experiments and RDD | Asmus Leth Olsen 35 | 7 | Thursday | 9-12 | Experiments 1: Simple randomization | Frederik Hjorth 36 | 8 | | 13-16| Experiments 2: Clustering, blocking, noncompliance | Frederik Hjorth 37 | 9 | Friday | 9-12 | Content analysis 1: Introduction, uses | Frederik Hjorth 38 | 10| | 13-16| Content analysis 2: Designs, reliability & validity | Frederik Hjorth 39 | 40 | For readings for each block, see the [Literature](#literature) section below. 41 | 42 | ### Dates 43 | 44 | Monday February 6 - Friday February 10, 2017. 45 | 46 | ### Location 47 | 48 | University of Copenhagen, Department of Political Science, Øster Farimagsgade 5, 1353 Copenhagen K. Teaching takes place in room [4.2.50](http://app.mapsindoors.net/ku/index.html#54b8c7503d4e4116842f1b8f). 49 | 50 | ### Class participation 51 | 52 | It is expected that you have read the texts for each day and participate actively in class discussions. 53 | 54 | ### Research paper 55 | 56 | Deadline for submitting a research paper is Wednesday, February 2 at noon. The research paper should reflect a quantitative/comparative/methodological aspect of your research and be no longer than 10 pages. It is expected that you prepare comment to all papers. The papers will be distributed before the course. 57 | 58 | ### Meals 59 | 60 | Lunch and coffee will be provided every day. On Tuesday, February 7, there will be a dinner for all course participants at [Madklubben Nørrebro](http://madklubben.dk/en/noerrebro/). 61 | 62 | ### Price 63 | 64 | For students enrolled at University of Copenhagen or political science departments at other Danish universities, course participation is free. For students at other departments, the fee is 1500 DKK. 65 | 66 | ### Literature 67 | 68 | #### 1: Logic 1 69 | 70 | - Lijphart, A. (1971) Politics and the Comparative method. *American Political Science Review*. 65 (3):682-693. (search for his interpretation of the core idea of PS) 71 | - Nørgaard. A. S. (2008) Political Science: Witchcraft or Craftsmanship? Standards for Good Research. *World Political Science Review*. 4(1):1-28. (A must read) 72 | - Dahler-Larsen, P., & Sylvest, C. (2013). Hvilken pluralisme?: Betragtninger om det kausale design og definitionen af god samfundsvidenskab. *Politik*, 16(2), 59-68. 73 | - Laitin, D. D. (2003). The perestroikan challenge to social science. *Politics & Society*, 31(1), 163-184. 74 | - Flyvbjerg, B. (2004). A perestroikan straw man answers back: David Laitin and phronetic political science. *Politics & Society*, 32(3), 389-416. 75 | 76 | #### 2: Logic 2 77 | 78 | - *The Journal Editors' Transparency Statement (JETS)*, available at [dartstatement.org/#!blank/c22sl](http://www.dartstatement.org/#!blank/c22sl) 79 | - Isaac, J. C. (2015). For a more public political science. *Perspectives on Politics*, 13(02), 269-283. 80 | - Leeper, T. J. (2016). Really Introductory Introduction to R, available at [github.com/leeper/Rcourse/raw/gh-pages/Intro2R/Intro2R.pdf](https://github.com/leeper/Rcourse/raw/gh-pages/Intro2R/Intro2R.pdf) 81 | 82 | #### 3: Regression 1 83 | 84 | - Angrist, J. D., & Pischke, J. S. (2014). *Mastering'metrics: The path from cause to effect*. Princeton University Pres, chapter 2. 85 | - Gilens, M., & Page, B. I. (2014). Testing theories of American politics: Elites, interest groups, and average citizens. *Perspectives on politics*, 12(03), 564-581. 86 | - Bashir, O. S. (2015). Testing Inferences about American Politics: A Review of the “Oligarchy” Result. *Research & Politics*, 2(4). 87 | 88 | #### 4: Regression 2 89 | 90 | - Larsen, M. V., Hjorth, F., Dinesen, P. & Sønderskov, K. M. (2016). Housing Bubbles and Support for Incumbents. *Annual Meeting of the American Political Science Association*. 91 | - Steenbergen, M. R., & Jones, B. S. (2002). Modeling Multilevel Data Structures. *American Journal of Political Science*, 46(1), 218-237. 92 | 93 | #### 5: Natural experiments 1 94 | 95 | - Hariri, Jacob (2012): Kausal inferens i statskundskaben, *Politica*. 96 | - Acemoglu, Daron, Simon Johnson, and James A. Robinson (2001): The Colonial Origins of Comparative Development: An Empirical Investigation, *American Economic Review*, 91 (5): 1369-1401. 97 | 98 | - Miguel, E., Satyanath, S., & Sergenti, E. (2004). Economic shocks and civil conflict: An instrumental variables approach. *Journal of political Economy*, 112(4), 725-753. 99 | 100 | #### 6: Natural experiments 2 101 | 102 | - Dunning, T. (2008). Improving Causal Inference: Strengths and Limitations of Natural Experiments. *Political Research Quarterly*, 61 (2), 282–293. 103 | - Verrier, Diarmuid B. (2012). Evidence for the influence of the mere-exposure effect on voting in the Eurovision Song Contest. *Judgment and Decision Making* 7 (5), 639-643. 104 | - Eggers, A. C., & Hainmueller, J. (2009). MPs for sale? Returns to office in postwar British politics. *American Political Science Review*, 103(04), 513-533. 105 | 106 | #### 7: Experiments 1 107 | 108 | - Angrist, J. D., & Pischke, J. S. (2014). *Mastering'metrics: The path from cause to effect*. Princeton University Pres, chapter 1. 109 | - Campbell, D. T., & Stanley, J. C. (1996): *Experimental and Quasi-experimental Designs for Research*. Chicago: Rand McNally. pp. 1-16. (a must read) 110 | - Gerber, A. S., Green, D. P., & Larimer, C. W. (2008). Social pressure and voter turnout: Evidence from a large-scale field experiment. *American Political Science Review*, 102(01), 33-48. 111 | - Gerber, A. S., & D. P. Green (2012): *Field Experiments: Design, Analysis, and Interpretation*. New York: W.W. Norton. Chapter 1. (a general intro to experiment) 112 | 113 | #### 8: Experiments 2 114 | 115 | - Gerber, A. S., & D. P. Green (2012): *Field Experiments: Design, Analysis, and Interpretation*. New York: W.W. Norton. Chapters 3-5. (blocking, clustering, covariate adjustment, one-sided noncompliance) 116 | - Nickerson, D. W. (2008): Is Voting Contagious? Evidence from Two Field Experiments. *American Political Science Review* 102 (February): 49-57. (focus on the design and the experiment) 117 | 118 | #### 9: Content analysis 1 119 | 120 | - Neuendorf, Kimberly A. (2002): The Content Analysis Guidebook, Sage. Chapters: 1, 3-7 (p. 1-26, 26 pages) 121 | - Krippendorff, Klaus (2008): Testing the Reliability of Content Analysis Data, in Krippendorff & Bock: The Content Analysis Reader, Sage (p. 350-357, 8 pages) 122 | - Carney, D. R., Jost, J. T., Gosling, S. D., & Potter, J. (2008). The secret lives of liberals and conservatives: Personality profiles, interaction styles, and the things they leave behind. *Political Psychology*, 29(6), 807-840 (34 pages) 123 | 124 | #### 10: Content analysis 2 125 | 126 | - Hansen, K. M., & Pedersen, R. T. (2008). Negative campaigning in a multiparty system. *Scandinavian Political Studies*, 31(4), 408-427 (20 pages) 127 | - King, G., Pan, J., & Roberts, M. E. (2013). How censorship in China allows government criticism but silences collective expression. *American Political Science Review*, 107(02), 326-343 (18 pages) 128 | -------------------------------------------------------------------------------- /data/03_gilens.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fghjorth/lqrps17/e801bd7e2d80de4c87379132780a4c6dfdbd3ebd/data/03_gilens.dta -------------------------------------------------------------------------------- /data/04_larsen.dta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fghjorth/lqrps17/e801bd7e2d80de4c87379132780a4c6dfdbd3ebd/data/04_larsen.dta -------------------------------------------------------------------------------- /data/04_steenbergen.rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fghjorth/lqrps17/e801bd7e2d80de4c87379132780a4c6dfdbd3ebd/data/04_steenbergen.rdata -------------------------------------------------------------------------------- /data/1_worldpop.csv: -------------------------------------------------------------------------------- 1 | year,worldpop 2 | 1950.0,2525779.0 3 | 1960.0,3026003.0 4 | 1970.0,3691173.0 5 | 1980.0,4449049.0 6 | 1990.0,5320817.0 7 | 2e3,6127700.0 8 | 2010.0,6916183.0 9 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Lqrps17 by fghjorth 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 |
17 |
18 |

Lqrps17

19 |

Information about and materials for graduate course "Logic of Quantitative Research in Political Science" at the University of Copenhagen, February 6-10, 2017

20 | 21 |

View the Project on GitHub fghjorth/lqrps17

22 | 23 | 24 | 29 |
30 |
31 |

32 | Logic of Quantitative Research in Political Science

33 | 34 |

This repo contains information about and materials for "Logic of Quantitative Research in Political Science", a five-day graduate-level course held at the University of Copenhagen, February 6-10, 2017. The course is taught by Frederik Hjorth, ph.d.

35 | 36 |

37 | Description

38 | 39 |

The course will use illustrative examples from the political science literature, and emphasizes the logic of research designs rather than their implementation in statistical software. The course equips students with concepts needed to understand the reasoning behind research designs and modeling in quantitative political science research.

40 | 41 |

The course is structured around five themes, one covered each day:

42 | 43 |
    44 |
  1. Logic of quantitative research
  2. 45 |
  3. Regression
  4. 46 |
  5. Experiments
  6. 47 |
  7. Natural Experiments
  8. 48 |
  9. Content analysis
  10. 49 |
50 | 51 |

The course covers the key methodological approaches within each theme as well as canonical research articles applying the relevant approach. For more details, see Course schedule below.

52 | 53 |

Students will also have the opportunity to present and receive feedback on their own ongoing work (see Research paper below).

54 | 55 |

56 | Signing up

57 | 58 |

To sign up for the course, please send an email to phdcourses@ifs.ku.dk, cc'ing me at fh@ifs.ku.dk.

59 | 60 |

61 | Course schedule

62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |
BlockDayTimeTheme
1Monday9-12Logic 1: Quantitative research designs
213-16Logic 2: Controversies about the quantitative approach
3Tuesday9-12Regression 1: Linear regression
413-16Regression 2: Binary DV and panel models
5Wednesday9-12Experiments 1: Simple randomization
613-16Experiments 2: Clustering, blocking, noncompliance
7Thursday9-12Natural experiments 1: Natural experiments and RDD
813-16Natural experiments 2: IV, difference-in-difference
9Friday9-12Content analysis 1: Introduction, uses
1013-16Content analysis 2: Designs, reliability & validity
135 | 136 |

For readings for each block, see the Literature section below.

137 | 138 |

139 | Dates

140 | 141 |

Monday February 6 - Friday February 10, 2017.

142 | 143 |

144 | Location

145 | 146 |

University of Copenhagen, Department of Political Science, Øster Farimagsgade 5, 1353 Copenhagen K.

147 | 148 |

149 | Class participation

150 | 151 |

It is expected that you have read the texts for each day and participate actively in class discussions.

152 | 153 |

154 | Research paper

155 | 156 |

Deadline for submitting a research paper is Wednesday, February 2 at noon. The research paper should reflect a quantitative/comparative/methodological aspect of your research and be no longer than 10 pages. It is expected that you prepare comment to all papers. The papers will be distributed before the course.

157 | 158 |

159 | Meals

160 | 161 |

Lunch and coffee will be provided every day. On Tuesday, February 7, there will be a dinner for all course participants at a Copenhagen restaurant (location tba).

162 | 163 |

164 | Price

165 | 166 |

For students enrolled at University of Copenhagen or political science departments at other Danish universities, course participation is free. For students at other departments, the fee is 1500 DKK.

167 | 168 |

169 | Literature

170 | 171 |

172 | 1: Logic 1

173 | 174 | 181 | 182 |

183 | 2: Logic 2

184 | 185 | 193 | 194 |

195 | 3: Regression 1

196 | 197 | 201 | 202 |

203 | 4: Regression 2

204 | 205 | 209 | 210 |

211 | 5: Experiments 1

212 | 213 | 219 | 220 |

221 | 6: Experiments 2

222 | 223 | 227 | 228 |

229 | 7: Natural experiments 1

230 | 231 | 236 | 237 |

238 | 8: Natural experiments 2

239 | 240 | 245 | 246 |

247 | 9: Content analysis 1

248 | 249 | 254 | 255 |

256 | 10: Content analysis 2

257 | 258 | 262 |
263 | 267 |
268 | 269 | 270 | 271 | 272 | -------------------------------------------------------------------------------- /javascripts/scale.fix.js: -------------------------------------------------------------------------------- 1 | var metas = document.getElementsByTagName('meta'); 2 | var i; 3 | if (navigator.userAgent.match(/iPhone/i)) { 4 | for (i=0; i1985,] 69 | 70 | -------------------------------------------------------------------------------- /scripts/03_reg1.R: -------------------------------------------------------------------------------- 1 | #definer filsti 2 | setwd("~/GitHub/lqrps17/") 3 | 4 | #indlæg nogle pakker 5 | require(haven) 6 | require(dplyr) 7 | require(ggplot2) 8 | 9 | #simuler et meget enkelt datas?t 10 | simdat<-data.frame(y=c(2,8,11,14),x=c(1,3,5,6)) 11 | 12 | #kovarians og varians 13 | kovariansxy<-cov(simdat$x,simdat$y) 14 | variansx<-var(simdat$x) 15 | variansy<-var(simdat$y) 16 | 17 | #udregn regressionskoefficient og bivariat korrelation 18 | regkoefx<-kovariansxy/variansx 19 | korrkoefxy<-kovariansxy/(sqrt(variansx)*sqrt(variansy)) 20 | 21 | #tjek 22 | summary(lm(y~x,data=simdat)) 23 | cor.test(simdat$x,simdat$y) 24 | 25 | #add additional variable, z 26 | simdat<-cbind(simdat,z=c(2,6,8,13)) 27 | 28 | #create x matrix for manual ols 29 | xmat<-as.matrix(cbind(const=1,simdat$x,simdat$z)) 30 | yvec<-simdat$y 31 | 32 | #create elements 33 | XY<-t(xmat)%*%yvec # X'Y 34 | XXi<-solve(t(xmat)%*%xmat) # (X'X)^-1 35 | 36 | #vector of coefficients 37 | XXi %*% XY 38 | 39 | #check again 40 | summary(lm(y~x+z,data=simdat)) 41 | cor.test(simdat$x,simdat$y) 42 | 43 | #indlæs data 44 | gd<-read_dta("data/03_gilens.dta") 45 | 46 | #fjern missing i dep var 47 | gd<-mutate(gd,outcome_rc=ifelse(OUTCOME==99,NA,OUTCOME)) 48 | 49 | #ols modeller 50 | m1ols<-lm(outcome_rc~pred50_sw,data=gd) 51 | m2ols<-lm(outcome_rc~pred90_sw,data=gd) 52 | m3ols<-lm(outcome_rc~pred50_sw+pred90_sw,data=gd) 53 | 54 | #resultat 55 | summary(m1ols) 56 | summary(m2ols) 57 | summary(m3ols) 58 | 59 | #lad os tjekke nogle typiske forudsætninger. er den funktionelle form lineær? 60 | plot(gd$pred50_sw,jitter(gd$outcome_rc)) 61 | 62 | #heteroskedasticitet? 63 | require(lmtest) 64 | bptest(m3ols,studentize=F) 65 | 66 | #normalfordelte residualer? 67 | hist(m3ols$residuals) 68 | 69 | #multikollinearitet? 70 | require(car) 71 | vif(m3ols) 72 | 73 | #hvor meget korrelerer holdninger for forskellige indkomstgrupper? 74 | plot(gd$pred50_sw,gd$pred90_sw) 75 | 76 | #formel test af korrelation 77 | cor.test(gd$pred50_sw,gd$pred90_sw) 78 | 79 | 80 | 81 | ### EKSTRA: robusthedstjek m binær afhængig 82 | 83 | #binær afhængig 84 | gd<-mutate(gd,outcome_rc01=ifelse(outcome_rc>0 & outcome_rc < 4,1,0)) 85 | 86 | #logit modeller 87 | m1logit<-glm(outcome_rc01~pred50_sw,data=gd,family="binomial") 88 | m2logit<-glm(outcome_rc01~pred90_sw,data=gd,family="binomial") 89 | m3logit<-glm(outcome_rc01~pred90_sw+pred50_sw,data=gd,family="binomial") 90 | 91 | #resultat 92 | summary(m1logit) 93 | summary(m2logit) 94 | summary(m3logit) 95 | 96 | #heteroskedasticitet? 97 | bptest(m3logit,studentize=F) 98 | 99 | #normalfordelte residualer? 100 | hist(m3logit$residuals) 101 | 102 | #multikollinearitet? 103 | vif(m3logit) 104 | 105 | ## plot predictions w ols and logit 106 | 107 | olspreddf<-as.data.frame(predict(m1ols,newdata=data.frame(pred50_sw=seq(0,1,.05)),se.fit=T)) 108 | 109 | logitpreddf<-as.data.frame(predict(m1logit,newdata=data.frame(pred50_sw=seq(0,1,.05)),type="response",se.fit=T)) 110 | 111 | preddf<-bind_rows(olspreddf[,1:2],logitpreddf[,1:2]) 112 | preddf$model<-rep(c("OLS","Logit"),each=21) 113 | 114 | ggplot(preddf,aes(x=rep(seq(0,1,.05),2),y=fit)) + 115 | geom_line() + 116 | geom_ribbon(aes(ymin=fit-2*se.fit,ymax=fit+2*se.fit),alpha=.1) + 117 | theme_bw() + 118 | facet_grid(.~model) + 119 | labs(x="Policy support",y="Pr(Success)") 120 | 121 | ggplot(logitpreddf,aes(x=seq(0,1,.05),y=fit)) + 122 | geom_line() + 123 | geom_ribbon(aes(ymin=fit-2*se.fit,ymax=fit+2*se.fit),alpha=.1) + 124 | theme_bw() 125 | -------------------------------------------------------------------------------- /scripts/04_reg2.R: -------------------------------------------------------------------------------- 1 | #definer filsti 2 | setwd("~/GitHub/lqrps17/") 3 | 4 | #indl?s nogle pakker 5 | require(haven) 6 | require(dplyr) 7 | require(stargazer) 8 | require(multiwayvcov) 9 | require(lmtest) 10 | require(lme4) 11 | 12 | #larsen et al data 13 | ld<-read_dta("data/04_larsen.dta") 14 | 15 | #overblik over data med glimpse() 16 | glimpse(ld) 17 | 18 | # estimer ren cross-sectional model 19 | m1<-lm(incsupport~hp_1yr,data=ld) 20 | summary(m1) 21 | 22 | #estimer model med year FE 23 | m2<-lm(incsupport~hp_1yr+factor(valgstedid)+factor(year),data=ld) 24 | summary(m2) # impossible to read :-/ 25 | 26 | #clustered se's at precinct level 27 | vcov_precinct<-cluster.vcov(m2,ld$valgstedid) 28 | clse_precinct<-sqrt(diag(vcov_precinct)) 29 | 30 | #alternative: re model 31 | m2re<-lmer(incsupport~hp_1yr+(1|valgstedid)+(1|year),data=ld) 32 | summary(m2re) 33 | 34 | #presentation in stargazer 35 | stargazer(m1,m2,m2,m2re,se=list(NULL,NULL,clse_precinct,NULL),style="apsr",type="text",omit="factor",omit.stat="f") 36 | 37 | 38 | # STEENBERGEN 39 | 40 | load("data/04_steenbergen.rdata") 41 | 42 | tbl4ols<-lm(support~tenurez+tradez+inclow+inchi+lright+olead+male+age,data=x) 43 | summary(tbl4ols) 44 | 45 | vcov_cntry<-cluster.vcov(tbl4ols,x$cntry) 46 | clse_cntry<-sqrt(diag(vcov_cntry)) 47 | 48 | tbl4re<-lmer(support~tenurez+tradez+inclow+inchi+lright+olead+male+age+(1|cntry),data=x) 49 | 50 | stargazer(tbl4ols,tbl4ols,tbl4re,se=list(NULL,clse_cntry,NULL),style="apsr",type="text",omit.stat="f") 51 | -------------------------------------------------------------------------------- /scripts/07_exp1.R: -------------------------------------------------------------------------------- 1 | setwd("~/GitHub/lqrps17/") 2 | 3 | require(readr) 4 | require(stargazer) 5 | require(dplyr) 6 | require(coefplot) 7 | 8 | ### Randomisering i praksis 9 | 10 | #1. lad os sige vi har et datasæt med 100 mennesker. 10 skal have treatment 11 | 12 | df<-data.frame(id=1:100) 13 | N<-nrow(df) 14 | m<-10 15 | 16 | #2. sæt et seed 17 | set.seed(1234) 18 | 19 | #3. tilfældigt tal for hver person 20 | df$randomnum<-sample(10000,N,replace=F) 21 | 22 | #4. sorter iht. det tilfældige tal (arrange() kommer fra dplyr) 23 | df<-arrange(df,randomnum) 24 | 25 | #5. assign treatment til de først m observationer 26 | df$treat<-0 27 | df$treat[1:m]<-1 28 | 29 | #6. for god ordens skyld: sorter tilbage til oprindelig rækkefølge 30 | df<-arrange(df,id) 31 | 32 | ### Gerber, Green & Larimer (2008) 33 | 34 | #indlæs data 35 | ggl<-read_csv("data/7_ggl.csv") 36 | 37 | #kig på data 38 | glimpse(ggl) 39 | 40 | #regression på turnout af exp treatment 41 | ols1<-lm(primary2006~messages,data=ggl) 42 | summary(ols1) 43 | 44 | #gør control til referencekategori 45 | ggl$treatmentfac<-relevel(as.factor(ggl$messages),ref="Control") 46 | 47 | #igen: regression på turnout af exp treatment 48 | ols2<-lm(primary2006~treatmentfac,data=ggl) 49 | summary(ols2) 50 | 51 | #vis på tabelform 52 | stargazer(ols2,type="text") 53 | 54 | #vis som koefficientplot 55 | coefplot(ols2,intercept=F,horizontal=T,color="black") 56 | 57 | #vigtigt balancecheck: balance på pre-treatment turnout? 58 | olsbc<-lm(primary2004~treatmentfac,data=ggl) 59 | summary(olsbc) -------------------------------------------------------------------------------- /scripts/08_exp2.R: -------------------------------------------------------------------------------- 1 | setwd("~/GitHub/lqrps17") 2 | 3 | require(readr) 4 | require(dplyr) 5 | require(broom) 6 | require(ggplot2) 7 | require(ri) 8 | 9 | # RANDOMIZATION INFERENCE 10 | 11 | set.seed(123456) 12 | y <- rnorm(500,100,15) 13 | Z <- sample(0:1,500,replace=T) 14 | cluster <- rep(1:50,each=10) 15 | perms <- genperms(Z, clustvar=cluster) # all possible permutations 16 | probs <- genprobexact(Z, clustvar=cluster) # probability of treatment 17 | ate <- estate(y,Z,prob=probs) # estimate the ATE 18 | ## Conduct Sharp Null Hypothesis Test of Zero Effect for Each Unit 19 | Ys <- genouts(y,Z,ate=0) # generate potential outcomes under sharp null of no effect 20 | distout <- gendist(Ys,perms, prob=probs) # generate sampling dist. under sharp null 21 | dispdist(distout, ate) # display characteristics of sampling dist. for inference 22 | 23 | #indlæs data 24 | ggd<-read_csv("data/8_gg.csv") 25 | 26 | #overblik over data 27 | glimpse(ggd) 28 | 29 | #limit to one-person households i kontrol eller canvas 30 | ggd<-subset(ggd,onetreat==1 & mailings==0 & phongotv==0 & persons==1) 31 | 32 | #ift. bogen: 33 | # VOTED hedder her v98 34 | # ASSIGNED hedder her persngrp 35 | # TREATED hedder her cntany 36 | 37 | #model for ITT 38 | ittmodel<-lm(v98~persngrp,data=ggd) 39 | summary(ittmodel) 40 | itt<-tidy(ittmodel)[2,2] 41 | 42 | #model for ITTD 43 | ittdmodel<-lm(cntany~persngrp,data=ggd) 44 | summary(ittdmodel) 45 | ittd<-tidy(ittdmodel)[2,2] 46 | 47 | #beregn CACE 48 | cace <- itt / ittd 49 | -------------------------------------------------------------------------------- /scripts/09_content1.R: -------------------------------------------------------------------------------- 1 | #set working dir 2 | setwd("~/GitHub/lqrps17/") 3 | 4 | require(pwr) 5 | 6 | pwr.2p.test(h=.3,n=100,sig.level=.05,alternative="two.sided") 7 | 8 | -------------------------------------------------------------------------------- /slides/01_logic1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fghjorth/lqrps17/e801bd7e2d80de4c87379132780a4c6dfdbd3ebd/slides/01_logic1.pdf -------------------------------------------------------------------------------- /slides/02_logic2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fghjorth/lqrps17/e801bd7e2d80de4c87379132780a4c6dfdbd3ebd/slides/02_logic2.pdf -------------------------------------------------------------------------------- /slides/03_regression1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fghjorth/lqrps17/e801bd7e2d80de4c87379132780a4c6dfdbd3ebd/slides/03_regression1.pdf -------------------------------------------------------------------------------- /slides/04_regression2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fghjorth/lqrps17/e801bd7e2d80de4c87379132780a4c6dfdbd3ebd/slides/04_regression2.pdf -------------------------------------------------------------------------------- /slides/07_experiments1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fghjorth/lqrps17/e801bd7e2d80de4c87379132780a4c6dfdbd3ebd/slides/07_experiments1.pdf -------------------------------------------------------------------------------- /slides/08_experiments2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fghjorth/lqrps17/e801bd7e2d80de4c87379132780a4c6dfdbd3ebd/slides/08_experiments2.pdf -------------------------------------------------------------------------------- /slides/09_contentanalysis1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fghjorth/lqrps17/e801bd7e2d80de4c87379132780a4c6dfdbd3ebd/slides/09_contentanalysis1.pdf -------------------------------------------------------------------------------- /slides/10_contentanalysis2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fghjorth/lqrps17/e801bd7e2d80de4c87379132780a4c6dfdbd3ebd/slides/10_contentanalysis2.pdf -------------------------------------------------------------------------------- /stylesheets/github-light.css: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 GitHub, Inc. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | */ 25 | 26 | .pl-c /* comment */ { 27 | color: #969896; 28 | } 29 | 30 | .pl-c1 /* constant, variable.other.constant, support, meta.property-name, support.constant, support.variable, meta.module-reference, markup.raw, meta.diff.header */, 31 | .pl-s .pl-v /* string variable */ { 32 | color: #0086b3; 33 | } 34 | 35 | .pl-e /* entity */, 36 | .pl-en /* entity.name */ { 37 | color: #795da3; 38 | } 39 | 40 | .pl-smi /* variable.parameter.function, storage.modifier.package, storage.modifier.import, storage.type.java, variable.other */, 41 | .pl-s .pl-s1 /* string source */ { 42 | color: #333; 43 | } 44 | 45 | .pl-ent /* entity.name.tag */ { 46 | color: #63a35c; 47 | } 48 | 49 | .pl-k /* keyword, storage, storage.type */ { 50 | color: #a71d5d; 51 | } 52 | 53 | .pl-s /* string */, 54 | .pl-pds /* punctuation.definition.string, string.regexp.character-class */, 55 | .pl-s .pl-pse .pl-s1 /* string punctuation.section.embedded source */, 56 | .pl-sr /* string.regexp */, 57 | .pl-sr .pl-cce /* string.regexp constant.character.escape */, 58 | .pl-sr .pl-sre /* string.regexp source.ruby.embedded */, 59 | .pl-sr .pl-sra /* string.regexp string.regexp.arbitrary-repitition */ { 60 | color: #183691; 61 | } 62 | 63 | .pl-v /* variable */ { 64 | color: #ed6a43; 65 | } 66 | 67 | .pl-id /* invalid.deprecated */ { 68 | color: #b52a1d; 69 | } 70 | 71 | .pl-ii /* invalid.illegal */ { 72 | color: #f8f8f8; 73 | background-color: #b52a1d; 74 | } 75 | 76 | .pl-sr .pl-cce /* string.regexp constant.character.escape */ { 77 | font-weight: bold; 78 | color: #63a35c; 79 | } 80 | 81 | .pl-ml /* markup.list */ { 82 | color: #693a17; 83 | } 84 | 85 | .pl-mh /* markup.heading */, 86 | .pl-mh .pl-en /* markup.heading entity.name */, 87 | .pl-ms /* meta.separator */ { 88 | font-weight: bold; 89 | color: #1d3e81; 90 | } 91 | 92 | .pl-mq /* markup.quote */ { 93 | color: #008080; 94 | } 95 | 96 | .pl-mi /* markup.italic */ { 97 | font-style: italic; 98 | color: #333; 99 | } 100 | 101 | .pl-mb /* markup.bold */ { 102 | font-weight: bold; 103 | color: #333; 104 | } 105 | 106 | .pl-md /* markup.deleted, meta.diff.header.from-file */ { 107 | color: #bd2c00; 108 | background-color: #ffecec; 109 | } 110 | 111 | .pl-mi1 /* markup.inserted, meta.diff.header.to-file */ { 112 | color: #55a532; 113 | background-color: #eaffea; 114 | } 115 | 116 | .pl-mdr /* meta.diff.range */ { 117 | font-weight: bold; 118 | color: #795da3; 119 | } 120 | 121 | .pl-mo /* meta.output */ { 122 | color: #1d3e81; 123 | } 124 | 125 | -------------------------------------------------------------------------------- /stylesheets/styles.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Noto Sans'; 3 | font-weight: 400; 4 | font-style: normal; 5 | src: url('../fonts/Noto-Sans-regular/Noto-Sans-regular.eot'); 6 | src: url('../fonts/Noto-Sans-regular/Noto-Sans-regular.eot?#iefix') format('embedded-opentype'), 7 | local('Noto Sans'), 8 | local('Noto-Sans-regular'), 9 | url('../fonts/Noto-Sans-regular/Noto-Sans-regular.woff2') format('woff2'), 10 | url('../fonts/Noto-Sans-regular/Noto-Sans-regular.woff') format('woff'), 11 | url('../fonts/Noto-Sans-regular/Noto-Sans-regular.ttf') format('truetype'), 12 | url('../fonts/Noto-Sans-regular/Noto-Sans-regular.svg#NotoSans') format('svg'); 13 | } 14 | 15 | @font-face { 16 | font-family: 'Noto Sans'; 17 | font-weight: 700; 18 | font-style: normal; 19 | src: url('../fonts/Noto-Sans-700/Noto-Sans-700.eot'); 20 | src: url('../fonts/Noto-Sans-700/Noto-Sans-700.eot?#iefix') format('embedded-opentype'), 21 | local('Noto Sans Bold'), 22 | local('Noto-Sans-700'), 23 | url('../fonts/Noto-Sans-700/Noto-Sans-700.woff2') format('woff2'), 24 | url('../fonts/Noto-Sans-700/Noto-Sans-700.woff') format('woff'), 25 | url('../fonts/Noto-Sans-700/Noto-Sans-700.ttf') format('truetype'), 26 | url('../fonts/Noto-Sans-700/Noto-Sans-700.svg#NotoSans') format('svg'); 27 | } 28 | 29 | @font-face { 30 | font-family: 'Noto Sans'; 31 | font-weight: 400; 32 | font-style: italic; 33 | src: url('../fonts/Noto-Sans-italic/Noto-Sans-italic.eot'); 34 | src: url('../fonts/Noto-Sans-italic/Noto-Sans-italic.eot?#iefix') format('embedded-opentype'), 35 | local('Noto Sans Italic'), 36 | local('Noto-Sans-italic'), 37 | url('../fonts/Noto-Sans-italic/Noto-Sans-italic.woff2') format('woff2'), 38 | url('../fonts/Noto-Sans-italic/Noto-Sans-italic.woff') format('woff'), 39 | url('../fonts/Noto-Sans-italic/Noto-Sans-italic.ttf') format('truetype'), 40 | url('../fonts/Noto-Sans-italic/Noto-Sans-italic.svg#NotoSans') format('svg'); 41 | } 42 | 43 | @font-face { 44 | font-family: 'Noto Sans'; 45 | font-weight: 700; 46 | font-style: italic; 47 | src: url('../fonts/Noto-Sans-700italic/Noto-Sans-700italic.eot'); 48 | src: url('../fonts/Noto-Sans-700italic/Noto-Sans-700italic.eot?#iefix') format('embedded-opentype'), 49 | local('Noto Sans Bold Italic'), 50 | local('Noto-Sans-700italic'), 51 | url('../fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff2') format('woff2'), 52 | url('../fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff') format('woff'), 53 | url('../fonts/Noto-Sans-700italic/Noto-Sans-700italic.ttf') format('truetype'), 54 | url('../fonts/Noto-Sans-700italic/Noto-Sans-700italic.svg#NotoSans') format('svg'); 55 | } 56 | 57 | body { 58 | background-color: #fff; 59 | padding:50px; 60 | font: 14px/1.5 "Noto Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; 61 | color:#727272; 62 | font-weight:400; 63 | } 64 | 65 | h1, h2, h3, h4, h5, h6 { 66 | color:#222; 67 | margin:0 0 20px; 68 | } 69 | 70 | p, ul, ol, table, pre, dl { 71 | margin:0 0 20px; 72 | } 73 | 74 | h1, h2, h3 { 75 | line-height:1.1; 76 | } 77 | 78 | h1 { 79 | font-size:28px; 80 | } 81 | 82 | h2 { 83 | color:#393939; 84 | } 85 | 86 | h3, h4, h5, h6 { 87 | color:#494949; 88 | } 89 | 90 | a { 91 | color:#39c; 92 | text-decoration:none; 93 | } 94 | 95 | a:hover { 96 | color:#069; 97 | } 98 | 99 | a small { 100 | font-size:11px; 101 | color:#777; 102 | margin-top:-0.3em; 103 | display:block; 104 | } 105 | 106 | a:hover small { 107 | color:#777; 108 | } 109 | 110 | .wrapper { 111 | width:860px; 112 | margin:0 auto; 113 | } 114 | 115 | blockquote { 116 | border-left:1px solid #e5e5e5; 117 | margin:0; 118 | padding:0 0 0 20px; 119 | font-style:italic; 120 | } 121 | 122 | code, pre { 123 | font-family:Monaco, Bitstream Vera Sans Mono, Lucida Console, Terminal, Consolas, Liberation Mono, DejaVu Sans Mono, Courier New, monospace; 124 | color:#333; 125 | font-size:12px; 126 | } 127 | 128 | pre { 129 | padding:8px 15px; 130 | background: #f8f8f8; 131 | border-radius:5px; 132 | border:1px solid #e5e5e5; 133 | overflow-x: auto; 134 | } 135 | 136 | table { 137 | width:100%; 138 | border-collapse:collapse; 139 | } 140 | 141 | th, td { 142 | text-align:left; 143 | padding:5px 10px; 144 | border-bottom:1px solid #e5e5e5; 145 | } 146 | 147 | dt { 148 | color:#444; 149 | font-weight:700; 150 | } 151 | 152 | th { 153 | color:#444; 154 | } 155 | 156 | img { 157 | max-width:100%; 158 | } 159 | 160 | header { 161 | width:270px; 162 | float:left; 163 | position:fixed; 164 | -webkit-font-smoothing:subpixel-antialiased; 165 | } 166 | 167 | header ul { 168 | list-style:none; 169 | height:40px; 170 | padding:0; 171 | background: #f4f4f4; 172 | border-radius:5px; 173 | border:1px solid #e0e0e0; 174 | width:270px; 175 | } 176 | 177 | header li { 178 | width:89px; 179 | float:left; 180 | border-right:1px solid #e0e0e0; 181 | height:40px; 182 | } 183 | 184 | header li:first-child a { 185 | border-radius:5px 0 0 5px; 186 | } 187 | 188 | header li:last-child a { 189 | border-radius:0 5px 5px 0; 190 | } 191 | 192 | header ul a { 193 | line-height:1; 194 | font-size:11px; 195 | color:#999; 196 | display:block; 197 | text-align:center; 198 | padding-top:6px; 199 | height:34px; 200 | } 201 | 202 | header ul a:hover { 203 | color:#999; 204 | } 205 | 206 | header ul a:active { 207 | background-color:#f0f0f0; 208 | } 209 | 210 | strong { 211 | color:#222; 212 | font-weight:700; 213 | } 214 | 215 | header ul li + li + li { 216 | border-right:none; 217 | width:89px; 218 | } 219 | 220 | header ul a strong { 221 | font-size:14px; 222 | display:block; 223 | color:#222; 224 | } 225 | 226 | section { 227 | width:500px; 228 | float:right; 229 | padding-bottom:50px; 230 | } 231 | 232 | small { 233 | font-size:11px; 234 | } 235 | 236 | hr { 237 | border:0; 238 | background:#e5e5e5; 239 | height:1px; 240 | margin:0 0 20px; 241 | } 242 | 243 | footer { 244 | width:270px; 245 | float:left; 246 | position:fixed; 247 | bottom:50px; 248 | -webkit-font-smoothing:subpixel-antialiased; 249 | } 250 | 251 | @media print, screen and (max-width: 960px) { 252 | 253 | div.wrapper { 254 | width:auto; 255 | margin:0; 256 | } 257 | 258 | header, section, footer { 259 | float:none; 260 | position:static; 261 | width:auto; 262 | } 263 | 264 | header { 265 | padding-right:320px; 266 | } 267 | 268 | section { 269 | border:1px solid #e5e5e5; 270 | border-width:1px 0; 271 | padding:20px 0; 272 | margin:0 0 20px; 273 | } 274 | 275 | header a small { 276 | display:inline; 277 | } 278 | 279 | header ul { 280 | position:absolute; 281 | right:50px; 282 | top:52px; 283 | } 284 | } 285 | 286 | @media print, screen and (max-width: 720px) { 287 | body { 288 | word-wrap:break-word; 289 | } 290 | 291 | header { 292 | padding:0; 293 | } 294 | 295 | header ul, header p.view { 296 | position:static; 297 | } 298 | 299 | pre, code { 300 | word-wrap:normal; 301 | } 302 | } 303 | 304 | @media print, screen and (max-width: 480px) { 305 | body { 306 | padding:15px; 307 | } 308 | 309 | header ul { 310 | width:99%; 311 | } 312 | 313 | header li, header ul li + li + li { 314 | width:33%; 315 | } 316 | } 317 | 318 | @media print { 319 | body { 320 | padding:0.4in; 321 | font-size:12pt; 322 | color:#444; 323 | } 324 | } 325 | --------------------------------------------------------------------------------