I have now had lunch with about half the class. If you haven't had
lunch and would like to or you already have had lunch and had so much
fun that you want to again or you want to talk about your paper over
lunch, please drop me an e-mail. Tuesdays and Fridays work best for
me, but I could do other days. I am also free for coffee and such in
the morning and afternoons.
I think that the most informative lunch discussions were my advice to
Olivia on how to get a House Tutor position and my suggestions to Dan
and Andrew about how to get your Ph.D. quickly and well. But perhaps
they were just being polite in listening . . .
;-)
Dave
--
David Kane
Lecturer in Government
617-563-0122
dkane(a)latte.harvard.edu
Ryan Thomas Moore writes:
> Do we need to
> "officially" tell you that we're taking 2001? Thanks for your time.
No. If you don't do the paper I'll assume that you are in 2001. Gary
and I will then coordinate the grading issues.
Dave
--
David Kane
Lecturer in Government
617-563-0122
dkane(a)latte.harvard.edu
Phillip Y. Lipscy writes:
[...]
> does the Gov2001 paper count for our Gov1000 grade? In
> the original syllabus, you indicated that we'd get a final grade based on
> adjusted %s from the exams. It's not a really big deal, but I would prefer not
> to get an Incomplete for Gov1000, since I might need to send my transcript out
> after the end of the semester. Just a clarification would be fine.
The GOV 2001 paper does count for the GOV 1000 course. It counts 20%,
as stated in the revised syllabus. (Originally, it counted for 30%,
but we took 10% away and gave that to the homeworks.) If you choose
the 2001 option, you will get an incomplete for 1000 until your grade
for the 2001 paper is in. Should you *really* not want an incomplete
on your transcript, nothing prevents you from doing the paper for 1000
and then taking 2001 anyway. ;-)
Dave
> Thanks!
> Phillip.
>
>
> -------------------------------------------------
> Phillip Y. Lipscy
> Perkins Hall Room #129
> 35 Oxford Street
> Cambridge, MA 02138
> (617)493-4893
> lipscy(a)fas.harvard.edu
>
> Ph.D. Candidate
> Harvard University, FAS, Department of Government
> -------------------------------------------------
>
>
> Quoting dkane(a)latte.harvard.edu:
>
> >
> > As you know from the syllabus, there is a paper for this class. If you take
> > 2001, then you do not need to do a paper for this class. Instead, whatever
> > grade you get in 2001 for the paper will count for 1000. If you plan on
> > doing
> > the paper for this class, please think about what you would like to write
> > on
> > and make an appointment to talk with me.
> >
> > Some people have expressed an interest in moving the due date for the final
> > later in January. The original date was selected to provide a big gap
> > between
> > the due date for the paper and the due date for the final. Since few people
> > are
> > doing the paper for GOV 1000, we could move the due date for the final
> > later.
> >
> > If you care (one way or the other), please let me know via private e-mail.
> > We
> > will probably go with class consensus on the issue.
> >
> > Dave
> >
> > --
> > David Kane
> > Lecturer In Government
> > 617-563-0122
> > dkane(a)latte.harvard.edu
> > _______________________________________________
> > gov1000-list mailing list
> > gov1000-list(a)fas.harvard.edu
> > http://www.fas.harvard.edu/mailman/listinfo/gov1000-list
> >
>
>
--
David Kane
Lecturer in Government
617-563-0122
dkane(a)latte.harvard.edu
Does anyone use a Mac at home to create a VNC session? I'm running OS9.x,
with MacSSH (or NiftyTelnet) and have the ATT VNC Viewer installed.
I can't seem to figure out port forwarding, or how to get the VNC viewer
to recognize the port.
thanks
Olivia.
The midterm will be handed out this Thursday the 14th at section and
will be due by noon on Thursday the 21st.
Each midterm count for 20%. The required problem sets (6-10) count
for 10%.
Dave
Stanislav Markus writes:
> Dear Dave,
>
> Given the recent post factum changes in the syllabus, I am a bit
> confused about the timing of the midterm - and also about the weighting
> of grades for midterms vs. homeworks.
>
> Thanks & happy thanksgiving,
> Stan
>
--
David Kane
Lecturer in Government
617-563-0122
dkane(a)latte.harvard.edu
Thanks to extended discussions with Gary, I now have better code for
homework 5. The key issue was that I read P_2 to be "party that won
election 2" in the same way that \nu_2 was "democratic vote in
election 2" and I_2 was "incumbent party in election 2". I should have
read it as "party that won election 1". The code below makes the
change and the results are much more similar in magnitude what we see
in the paper --- although they are still far from identical.
The key line that specifies this is at the bottom of page 1150. Given
the notation, I had just assumed that this was a misprint. My mistake.
Attentive readers of the mailing list will note that Ryan (especially)
and Traci raised this as an issue last week.
The code is below. Only a couple of key changes were required (I also
changed the coding of the P_2 variable to be 1 and -1, as opposed to
1, 0, since this is what it is in the paper.
Dave
load.data <- function(end.year = 902){
## Simple function for looping through years and loading up the
## appropriate data. Note that different years have different
## numbers of rows (as well as different district and state (!)
## numbering schemes) so you need to be careful. Thanks to Olivia
## for helpful clues. I am still not sure if, instead of loading up
## the data all at once, I should just load two at a time, but we'll
## see.
## First we need an empty dataframe that we will add things on to.
result <- data.frame()
## Then we do our loop. Note that this code is somewhat inefficient since
## each time we read in a new dataframe we append that to are running
## total. This is (computationally) costly since it forces R to find
## somewhere to put the new (larger) object as opposed to it having already
## allocated the space for it, as we did in previous simulations. Alas,
## pre-allocation would be hard to do since, before we start, we do not know
## how big the files are. But this goes quick enough that the inefficiency
## isn't too bad.
## Note that my first version had several bugs. I used end.year instead of
## year in the loop. I forget to deal with missing values. Running summary on
## the output dataframe revealed the bugs.
for(year in seq(898, end.year, by = 2)){
file.name <- paste("da6311_LREC.yr", year, sep = "")
x <- read.table(file.name,
col.names = c("state", "district", "incumb", "dem", "rep"),
na.strings = "-9")
x$year <- 1000 + year
result <- rbind(result, x)
}
result
}
clean.data <- function(x){
## Simple function that cleans up the results of load.data. Mainly just an
## exercise in new variables and bad data deletion. Note that it is not clear
## if
x <- x[! (x$dem %in% c(0, 1, NA) | x$rep %in% c(0, 1, NA) | x$incumb %in% c(NA, 3)),]
x$d.perc <- x$dem / (x$dem + x$rep)
x$party <- ifelse(x$dem > x$rep, 1, -1)
x
}
one.year <- function(x, year){
## Simple function which takes a dataframe and a year, subsets out that
## year's data (and the previous year's data) from x, merges them together,
## ensures that the variable names are sensible (by only keeping the
## variables that it needs from each year), runs a regression and returns the
## regression coefficient on incumbency.
this.year <- x[x$year %in% c(year), ]
last.year <- x[x$year %in% c(year - 2), ]
## Note that this merge will drop observations without matching state's and
## district's, but I think that this is probably OK.
x <- merge(this.year[c("state", "district", "d.perc", "incumb")],
last.year[c("state", "district", "d.perc", "party")],
by = c("state", "district"),
suffixes = c("", ".old"))
lm.obj <- lm(d.perc ~ d.perc.old + party + incumb, data = x)
## I just return the coefficient. Of course, if I were cool, I would consider
## returning a vector with a bunch of useful things (say sophomore surge and
## retirement slump) or even the entire lm object. In the latter case
coef(lm.obj)["incumb"]
}
many.years <- function(x, start.year, end.year){
## Function for looping through many years and returning a matrix
## with year and \psi in it. You pass in a clean dataset as well as
## a start.year and end.year.
## Make the years. We want all years from start to end, by 2, but
## leaving out those that end with 2. Note the use of modulo arithmetic. Of
## course, you could do this in a one liner, but at the cost of readability.
years <- seq(start.year, end.year, by = 2)
years.with.a.2 <- years %% 10 == 2
years <- years[! years.with.a.2]
## Set up a matrix to hold the results.
result <- matrix(NA, length(years), 2)
for(i in 1:length(years)){
result[i,] <- c(years[i], one.year(x, years[i]))
}
## Easier to work with appropriately named dataframes as a final result.
result <- as.data.frame(result)
names(result) <- c("year", "advantage")
result
}
## Simple function that generates the final matrix, assumes that you're working
## directory is set to the directory in which the raw files are. After loading
## this file, you should just be able to type do.all().
do.all <- function(){
x <- load.data(992)
clean <- clean.data(x)
results <- many.years(clean, 1900, 1992)
results
}
--
David Kane
Lecturer in Government
617-563-0122
dkane(a)latte.harvard.edu
I think that the key error here is
for(yr in seq(1900,1990,by = 2)){
if(! yr %in% years.with.a.2){
Note that the construction
yr %in% years.with.a.2
produces a vector of TRUE/FALSES. Take the negation, flips
everything. But "if" clauses do not deal with vectors. (If you really
wanted to vectorize this, you would use an "ifelse".) The "if" clause
just checks the first value of the vector. You probably want something
like:
if(! any(yr %in% years.with.a.2)){
In this case, the "any" will report TRUE if yr is anywhere in the
list, which is what you want, I think.
Dave
rtmoore(a)fas.harvard.edu writes:
> When I run this program, I get a nice vector of psi's. The strange thing is,
> it ignores my attempt to remove the years that end in 2 from my vector. I get
> a vector of psi's that has 46 values--every election from 1900 to 1990. Why
> doesn't out the reapportionment years?
>
> Thanks (again),
> Ryan
>
>
> superloop <- function(dataframe){
> psi <- data.frame(year = 1900:1990, psi = NA)
> years <- seq(1900,1990, by = 2)
> years.with.a.2 <- years %% 10 == 2
> for(yr in seq(1900,1990,by = 2)){
> if(! yr %in% years.with.a.2){
> this.year <- dataframe[dataframe$year %in% c(yr),]
> last.year <- dataframe[dataframe$year %in% c(yr - 2),]
> x <- merge(this.year[c("state","district", "dempct","incumb","dwin")],
> last.year[c("state","district","dempct")], by = c("state","district"), suffixes
> =
> c("",".old"))
> object <- lm(dempct ~ dempct.old + dwin + incumb, data = x)
> psi$year[psi$year == yr] <- yr
> psi$psi[psi$year == yr] <- object$coefficients[4]
> }}
> psi <- psi[! psi$psi %in% c(NA),]
> return(psi)
> }
>
>
>
>
>
>
>
>
>
>
>
>
> Quoting Dave Kane <dkane(a)latte.harvard.edu>:
>
> > Ryan Thomas Moore writes:
> > >
> > > The "assign dwin, incumb to zero" method from other emails seems
> > > unjustified to me. To predict the nu2 from nu1 = .45, we
> > > need values for P2 and I2. If we're assuming that the party of the
> > winner
> > > this year is republican, ok -- but why? If we're to assume that there's
> > > no incumbent, again, no problem, but these are not anywhere in the
> > problem
> > > set, right? Or am I missing it?
> >
> > It was a mistake in the problem set not to specify the values for the
> > other variables to use in making the prediction. So, I choose zero for
> > them somewhat arbitrarily. But, they have to be set to *something* in
> > order to generate a prediction. What things it is sensible to set them
> > to is something that we will discuss in class.
> >
> > Dave
> >
> >
> > > Thanks,
> > > Ryan
> > >
> > > ------------------------------------------
> > > Ryan T. Moore ~ Government & Social Policy
> > > Ph.D. Candidate ~ Harvard University
> > >
> > >
> >
> > --
> > David Kane
> > Lecturer in Government
> > 617-563-0122
> > dkane(a)latte.harvard.edu
> >
>
>
>
>
--
David Kane
Lecturer in Government
617-563-0122
dkane(a)latte.harvard.edu
I am pleased to announce that Gary King will be joining your
hard-working GOV 1000 teaching staff. Gary will be working with us on
all aspects of the class, although (obviously) his influence will be
felt more in some places (class lectures) than in others (e-mail
messages). We will be announcing some organization changes over the
weekend and at class on Monday. Most importantly, Gary will be giving
the lecture on Monday. His focus will be on the fundamentals of
probability. Gary's lecture will be largely self-contained, but you
may find it useful to review Moore/McCabe (or an intro statistics book
of your choice) and/or to take a look at Appendix A in Neter. I will
be giving the lecture on the 18th (after the midterm) on matrix
algebra and linear regression. We are still working on the details for
the 4 lectures after that.
Most of the major aspects of the class will remain unchanged. We will
still be having another midterm, final, paper and 4 problem sets. I am
working on an update of the syllabus that outlines the rest of the
semester.
Both Tao and I are excited about Gary's decision to work with us on
GOV 1000.
Dave
--
David Kane
Lecturer in Government
617-563-0122
dkane(a)latte.harvard.edu
Here is my key R code for generating the estimates of the effect of
incumbency in US house elections. I have tried to be verbose in my
comments, but questions are always welcome. There will be an answer
key for all of problem set 5 available in class on Monday.
I will also be providing an update over the weekend on some
organization changes that we are making to the course.
Dave
load.data <- function(end.year = 902){
## Simple function for looping through years and loading up the
## appropriate data. Note that different years have different
## numbers of rows (as well as different district and state (!)
## numbering schemes) so you need to be careful. Thanks to Olivia
## for helpful clues. I am still not sure if, instead of loading up
## the data all at once, I should just load two at a time, but we'll
## see.
## First we need an empty dataframe that we will add things on to.
result <- data.frame()
## Then we do our loop. Note that this code is somewhat inefficient since
## each time we read in a new dataframe we append that to are running
## total. This is (computationally) costly since it forces R to find
## somewhere to put the new (larger) object as opposed to it having already
## allocated the space for it, as we did in previous simulations. Alas,
## pre-allocation would be hard to do since, before we start, we do not know
## how big the files are. But this goes quick enough that the inefficiency
## isn't too bad.
## Note that my first version had several bugs. I used end.year instead of
## year in the loop. I forget to deal with missing values. Running summary on
## the output dataframe revealed the bugs.
for(year in seq(898, end.year, by = 2)){
file.name <- paste("da6311_LREC.yr", year, sep = "")
x <- read.table(file.name,
col.names = c("state", "district", "incumb", "dem", "rep"),
na.strings = "-9")
x$year <- 1000 + year
result <- rbind(result, x)
}
result
}
clean.data <- function(x){
## Simple function that cleans up the results of load.data. Mainly just an
## exercise in new variables and bad data deletion. Note that it is not clear
## if this is the correct subsetting to use.
x <- x[! (x$dem %in% c(0, 1, NA) | x$rep %in% c(0, 1, NA) | x$incumb %in% c(NA, 3)),]
x$d.perc <- x$dem / (x$dem + x$rep)
x$party <- ifelse(x$dem > x$rep, 1, 0)
x
}
one.year <- function(x, year){
## Simple function which takes a dataframe and a year, subsets out that
## year's data (and the previous year's data) from x, merges them together,
## ensures that the variable names are sensible (by only keeping the
## variables that it needs from each year), runs a regression and returns the
## regression coefficient on incumbency.
this.year <- x[x$year %in% c(year), ]
last.year <- x[x$year %in% c(year - 2), ]
## Note that this merge will drop observations without matching state's and
## district's, but I think that this is probably OK.
x <- merge(this.year[c("state", "district", "d.perc", "incumb", "party")],
last.year[c("state", "district", "d.perc")],
by = c("state", "district"),
suffixes = c("", ".old"))
lm.obj <- lm(d.perc ~ d.perc.old + party + incumb, data = x)
## I just return the coefficient. Of course, if I were cool, I would consider
## returning a vector with a bunch of useful things (say sophomore surge and
## retirement slump) or even the entire lm object. In the latter case
coef(lm.obj)["incumb"]
}
many.years <- function(x, start.year, end.year){
## Function for looping through many years and returning a matrix
## with year and \psi in it. You pass in a clean dataset as well as
## a start.year and end.year.
## Make the years. We want all years from start to end, by 2, but
## leaving out those that end with 2. Note the use of modulo arithmetic. Of
## course, you could do this in a one liner, but at the cost of readability.
years <- seq(start.year, end.year, by = 2)
years.with.a.2 <- years %% 10 == 2
years <- years[! years.with.a.2]
## Set up a matrix to hold the results.
result <- matrix(NA, length(years), 2)
for(i in 1:length(years)){
result[i,] <- c(years[i], one.year(x, years[i]))
}
## Easier to work with appropriately named dataframes as a final result.
result <- as.data.frame(result)
names(result) <- c("year", "advantage")
result
}
## Simple function that generates the final matrix, assumes that you're working
## directory is set to the directory in which the raw files are. After loading
## this file, you should just be able to type do.all().
do.all <- function(){
x <- load.data(992)
clean <- clean.data(x)
results <- many.years(clean, 1900, 1992)
results
}
--
David Kane
Lecturer in Government
617-563-0122
dkane(a)latte.harvard.edu
I think that I may have mis-e-mailed on the topic of this week's
readings. According to the updated syllabus on the web site, we were
supposed to have done Neter chapters 1-5 for last week, 6,7, 11 for
this coming Monday and 8,9,10 for the 4th. I will also be adding an
article or two.
Sorry for any confusion.
Dave
--
David Kane
Lecturer in Government
617-563-0122
dkane(a)latte.harvard.edu