Teaching

I have served as a TA for undergraduate Intro to American Politics and Comparative Politics classes. I have also served as the TA for the graduate level Research Methods I and Research Methods II classes (twice each).

  • Introduction to American Politics
    • A basic introduction to American Politics. Topics include: American Parties and their development, The Legislative Branch, The Executive Branch, Federalism in the U.S. States, Campaign Finance and Election Law, Civil Rights, the American Bureaucracy, etc. As TA I was responsible for two discussion sections (~50 students total) that met weekly to discuss topics related to the lectures as well as the administration of quizzes and all assignment grading.
  • Introduction to Comparative Politics
    • A basic introduction to Comparative Politics. Students examine various institutions in governance across the world. Topics include: Party Systems, Legislatures, Executive Branches, Federalism vs. Unitary Governance, Election Systems, Political Culture, etc. As TA I was responsible for two discussion sections (~50 students total) that met weekly to discuss topics related to the lectures as well as the administration of quizzes and all assignment grading.
  • PLSC 500 Research Methods I
    • This course covers a wide selection of content necessary for graduate students beginning their research journeys. Topics covered include research ethics, Philosophy of Science, Statistics, changes to Political Science methods over time, and more. As the TA for the class I was responsible for teaching the students how to code and get started with R.
  • PLSC 501 Research Methods II
    • The next step in students’ research journeys, this class takes a deeper dive into statistics and modeling. Topics covered include elementary matrix math, linear regression via Ordinary Least Squares (OLS), regression with limited dependent variables, assumptions of common models, and more. As the TA for the class I was responsible for teaching the students more in depth coding techniques in R as well as other technical aspects of scholarship e.g. latex, data collection, data literacy, etc.

As an instructor of record at Binghamton University I have developed and taught two classes independent from any supervising faculty: a seminar class “American Elections and Campaigns” and a simulation-style course “U.S. Campaigns and Activism”

  • PLSC 382A “U.S. Campaigns and Activism”


  • PLSC 481J “American Elections & Campaigns”
  • Introduction to Research Methods for Undergraduates
  • The American Congress
  • Public Opinion and Voting Behavior

Rearrange String

A very useful string rearranger, developed for merging congressional data using member names stored in different formats.

Code
rearrange_string = function(input_string, output_structure, remove = NULL) {
  # Split the input string based on spaces
  split_string = strsplit(input_string, "\\s+")[[1]]
  
  # Remove specified elements using successive gsub() commands
  if (!is.null(remove)) {
    for (element in remove) {
      split_string = gsub(element, "", split_string, fixed = TRUE)
    }
  }
  
  # Analyze for suffixes
  suffixes = c("Jr.", "Sr.", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X","Jr.,", "Sr.,", "I,", "II,", "III,", "IV,", "V,", "VI,", "VII,", "VIII,", "IX,", "X,")
  for(i in seq_along(split_string)){
    if (split_string[i] %in% suffixes){
      if (i > 1){
        split_string[i] = ""
      }
    }
  }
  
  # Split the output structure based on commas
  output_indices = as.numeric(strsplit(output_structure, ",")[[1]])
  
  # Filter out empty elements
  desired_elements = split_string[split_string != ""]
  
  # Rearrange the elements based on the output structure
  rearranged_elements = desired_elements[output_indices]
  
  # Remove "NA" elements
  rearranged_elements = rearranged_elements[!is.na(rearranged_elements)]
  
  # Combine the rearranged elements into a string
  output_string = paste(rearranged_elements, collapse = " ")
  
  return(trimws(output_string))
}

# Example Use

vector1 = c("Charles Robinson", "Andrea LaSalle", "Merve Yasmina", "David Clark")

vector2 = c("Robinson, Charles", "LaSalle, Andrea", "Yasmina, Merve", "Clark, David")

# These vectors contain the same people but how can we get R to realize that?
# rearrange_string will cut the strings up, number the pieces and rearrange them however you designate.
# It will also remove elements, e.g. commas, if you want.

vector2b = sapply(vector2, rearrange_string, output_structure = "2,1", remove = ",")

vector1==vector2b
Robinson, Charles   LaSalle, Andrea    Yasmina, Merve      Clark, David 
             TRUE              TRUE              TRUE              TRUE 

Remove Commas

A simple function that trims commas from numbers and returns in numeric format. Very good for working with currency or data collection where numbers were stored with commas or as strings.

Code
removeCommas = function(input) {
  # Remove commas
  cleaned = gsub(",", "", input)
  
  # Convert to numeric format
  result = as.numeric(cleaned)
  
  return(result)
}

# Example Use

vector = c("1,000", "213,453", "90", "1", "2,982,124,234.00")

vector
[1] "1,000"            "213,453"          "90"               "1"               
[5] "2,982,124,234.00"
Code
vector*3 # Won't work these are "character" type values and if you try to coerce using "as.numeric" the ones with commas will be NA
Error in vector * 3: non-numeric argument to binary operator
Code
removeCommas(vector)*3
[1]       3000     640359        270          3 8946372702

Success!

Esample

This function subsets a data frame to include only those observations used in a given model, a handy post-estimation tool inspired by Stata’s esample command.

Code
esample = function(m, data){
  e=rownames(as.matrix(resid(m)))
  sample=data[e,]
  return(sample)
}

set.seed(12345)

x = rnorm(100, 200, 12)
noise = rnorm(100, 5, 1)

data = data.frame(
  y = ((x + x/noise)*5.35*x)*1^(noise),
  x = x ,
  x2 = c(seq(1:50),seq(1:25), rep(NA,25)),
  x3 = c(NA,rnorm(99,25,25))
)

model = lm(data=data, y ~ x+x2+x3)

nobs(model)
[1] 74
Code
newdata = esample(model, data = data)

newdata
          y        x x2         x3
2  293122.0 208.5136  2 -10.903643
3  250152.1 198.6884  3   9.268509
4  257614.4 194.5580  4  31.088044
5  274548.9 207.2706  5  51.459056
6  207912.8 178.1845  6  45.783720
7  279647.9 207.5612  7  27.630295
8  238534.8 196.6858  8 -18.542827
9  252188.2 196.5901  9  41.131175
10 226945.7 188.9681 10  27.427606
11 267002.6 198.6050 11  23.081658
12 334817.1 221.8077 12  49.798767
13 259339.1 204.4475 13   3.518731
14 263579.6 206.2426 14  17.960508
15 234833.1 190.9936 15  76.656182
16 287882.9 209.8028 16   9.711176
17 230616.7 189.3637 17  32.890321
18 242090.5 196.0211 18  41.507334
19 277695.6 213.4486 19 -18.055060
20 266708.7 203.5847 20 -28.365651
21 270316.9 209.3555 21  26.723640
22 293042.5 217.4694 22  46.695544
23 234933.9 192.2681 23 -32.251104
24 202918.4 181.3624 24  21.245243
25 213143.7 180.8275 25  18.280455
26 331298.6 221.6612 26  69.783301
27 265782.6 194.2202 27  41.806701
28 267618.7 207.4446 28  19.767472
29 309970.4 207.3455 29  25.304563
30 265018.8 198.0523 30  63.352922
31 270790.3 209.7425 31  26.932295
32 320724.9 226.3620 32  26.960938
33 318702.5 224.5903 33   5.518473
34 325589.2 219.5893 34  29.163992
35 249391.6 203.0513 35  31.633114
36 284186.9 205.8943 36  47.269518
37 257341.4 196.1110 37  13.302791
38 204042.8 180.0554 38  43.959364
39 312844.7 221.2128 39   8.956591
40 261559.1 200.3096 40  40.691796
41 307168.0 213.5421 41  31.208253
42 199662.2 171.4357 42   7.498105
43 230232.2 187.2768 43  10.814960
44 306970.3 211.2457 44  18.465152
45 283656.2 210.2534 45  -1.597126
46 298849.9 217.5288 46  22.340784
47 231165.8 183.0428 47  44.277593
48 267935.6 206.8088 48  93.685089
49 268118.5 206.9983 49  22.901631
50 217127.3 184.3184 50  38.589191
51 259610.6 193.5154  1  43.821530
52 315050.3 223.3723  2   4.783147
53 256834.9 200.6431  3  50.027996
54 276333.5 204.2200  4  36.401313
55 237414.9 191.9483  5 -10.856258
56 267774.5 203.3354  6  18.367380
57 266765.1 208.2941  7  41.044229
58 286299.2 209.8855  8  14.624474
59 326427.0 225.7408  9  13.510608
60 194294.6 171.8367 10   5.187650
61 266139.2 201.7951 11  -3.963478
62 215026.5 183.8896 12  42.772250
63 276457.2 206.6396 13  56.690044
64 313608.8 219.0796 14  21.421224
65 248891.0 192.9574 15  12.124277
66 205453.8 178.0115 16  62.072280
67 279562.2 210.6577 17  20.935277
68 325192.0 219.1219 18  26.042729
69 261107.9 206.2023 19  37.075997
70 218597.8 184.4519 20  -4.503179
71 256829.5 200.6554 21   8.410657
72 224940.3 190.5842 22   9.133753
73 225211.9 187.4078 23   7.450924
74 325766.0 227.9661 24  39.421259
75 327822.5 216.8325 25 -27.827009

Exactly 74 observations and at the appropriate indices (2:75)!