--- title: "Assignment 1" author: "Econ 4210" date: "20/01/2021" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE) # Set the...

1 answer below »
HTML DOCUMENT WITH RCODE



--- title: "Assignment 1" author: "Econ 4210" date: "20/01/2021" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE) # Set the graphical theme ggplot2::theme_set(ggplot2::theme_light()) # Load package library(tidyverse) library(AER) ``` # Instructions Work through each code chunk and replace `eval = F` with `eval = T` and replace `...` with the appropriate code. Run code chunks one by one using the "play" button or "shift+command+enter."^footnote[You can also run one line at a time highlighting it and pressing "command+enter."] # Political Polarization ## Data management ### Load data on political views This dataset is from Voteview, a website by political scientists Keith Poole and Howard Rosenthal that freely provides information on congressional roll call votes in the United States. The data goes back to the first U.S. congress in 1789, and includes votes from both the Senate and the House of Representatives. In addition the the votes themselves, Voteview's datasets include indicators of politicians' ideological positions, which have been estimated using NOMINATE. See also the 'Details' section below. 1. Create data frame called `raw` from the url given below. ```{r} # load data from url raw <- read_csv('https://voteview.com/static/data/out/members/hsall_members.csv')="" ```="" ###="" subsetting="" data="" in="" class,="" we="" discussed="" filtering="" data="" when="" a="" variable="" takes="" on="" a="" specific="" value="" or="" range="" of="" values="" (using="" "="="" or="" "="">", for example. You can also do the opposite - subset data if a variable does not take on particular value. To do this, you can use the "!=", `filter(var != x)`. Another operator, `%in%` checks for matches in a list and returns `TRUE` if matches are found. For example, `filter(var %in% c(5,6,7))` checks to see if the variable `var` takes on values in the list 5,6,7 and returns `TRUE` if matches are made. Since this is a logical operator, it can be used in `filter`. 1. Filter the data so that `chamber` does not equal 'President'. 2. Filter the data so that `party_code` is in the list `c(100,200)`. 3. Filter the data so that only values of congress greater than 45 are retained. ```{r, eval = F} df <- ...="" %="">% filter(chamber ..., party_code ... c(100,200 ), congress > 45) ``` > Check: your data should now contain 37620 rows` ### Mutate 1. Create a variable called `year` that is equal to `1789 + 2 * (congress-1)`. 2. `party_code` is numeric and contains values 100 (Democrats) or 200 (Republicans). Create a variable called `party` that is a factor with the labels "Democrats" or "Republicans". 3. Create a dummy variable for 'moderate' called `moderate` if the variable `nominate_dim1` takes on values between (-0.5 to +0.5). ```{r, eval = F} df <- df="" %="">% mutate(year = ..., party = factor(..., labels = c("Democrats", "Republicans")), moderate = ifelse(... > -0.5 & ... < 0.5,="" 1,="" 0))="" #="" closely="" inspect="" this="" line="" to="" make="" sure="" you="" understand="" it.="" ```="" ##="" data="" visualization="" the="" variable="" `nominate_dim1`="" is="" an="" index="" in="" the="" range="" of="" [-1,1]="" indicating="" a="" member's="" ideological="" position="" on="" economic="" matters,="" also="" referred="" to="" as="" the="" 'left-right'="" spectrum.="" lower="" values="" indicate="" left-wing="" positions,="" higher="" values="" indicate="" right-wing="" positions.="" lets="" examine="" how="" this="" index="" has="" changed="" over="" time="" by="" party="" and="" chamber="" 1.="" create="" a="" data="" frame="" called="" `fig`="" that="" contains="" the="" mean="" of="" `nominate_dim1`="" and="" `moderate`="" by="" `year`,="" `chamber`,="" and="" `party`="" using="" the="" combination="" of="" `group_by()`="" and="" `summarise()`.="" give="" mean="" if="" `nominate_dim1`="" the="" variable="" name="" `index`,="" call="" the="" mean="" of="" `moderate`="" `prop_moderate`="" 2.="" filter="" for="" rows="" since="" the="" year="" 1900.="" [note:="" `moderate`="" is="" a="" dummy="" variable.="" the="" mean="" of="" a="" dummy="" variable="" gives="" the="" **proportion**="" of="" 1's="" --="" proportion="" of="" moderates="" in="" this="" case.]="" ```{r,="" eval="F}" fig=""><- ...="" %="">% group_by(..., ..., ...) %>% summarise(index = mean(..., na.rm = T), moderate = mean(..., na.rm = T)) %>% filter(year > ...) ``` > check: fig should have 244 rows. ### Polarization by chamber and party The structure of the data frame `fig` is that it contains four groups, by year (Chamber $\times$ party). We want to plot the mean of the variable `index` you created above by party, separately by chamber. 1. Plot index against year. Use both a `point` and `line` geom. 1. Set the `colour` aesthetic to `party`. 1. To get separate plots by group, we can use the command `facet_grid` which takes a one-sided formula (starts with `~`). Set the variable to `chamber`. ```{r, eval = F} ggplot(fig, aes(y = ... , x = ..., color = ...)) + geom_line() + geom_point(shape = 1) + facet_grid(~...) + theme(legend.position = 'bottom') ``` ### Are there more extreme members? Create a the same figure as the one above, but replace `index` on the $y$-axis with `moderate`. ```{r, eval = F} ggplot(... , aes(y = ..., x = ..., color = ...)) + geom_line() + facet_grid(~ ...) + theme(legend.position = 'bottom') ``` ### Within and between party views The figures above show how average "left-right" political possitions have changed over time by party and chamber. Now we look at the distribution of views **within** party. To do so, we go back to the data frame `df`. 2. Filter `df` (but do not write over `df`) so that it contains the years 1971,1981,1991,2001,2011, and 2019, 3. Filter `df` so that it contains data on only the House. 4. Plot the density of `noninate_dim1` 5. Set `fill` aesthetic to `party` 6. `facet_wrap` by `year` 7. Set `alpha` to .5 8. label your figure with appropriate $y$, $x$ and title labels using `labs()`. ```{r, eval = F} df %>% filter(year %in% ..., chamber == ...) %>% ggplot(aes(x = nominate_dim1, fill = ...)) + geom_density(alpha = ...) + facet_wrap(~year) + labs() ``` # Polarization of the the labour market Economists have used the term 'polarization' in various ways in the past. More recently the term has picked up usage in the debate of how the labour market has been changing in the US, Canada and Europe. In particular, "wage polarization" occurs, broadly speaking, when there is growth at the top of the wage distribution (rich getting richer) and perhaps the bottom, while no growth or decline in the middle. Employment polarization usually refers to declining employment shares in jobs that require medium skill and pay roughly medium wages. [Here is an overview](https://en.wikipedia.org/wiki/Polarization_(economics)). Here we use data from the Merged Outgoing Rotation Group (MORG) extracts of the Current Population Survey which contains information on the U.S. labour force. ```{r} ## Load morg data morg <- read_rds(url("https://github.com/ben-sand/ben-sand.github.io/blob/master/files/morg.rds?raw="true"))" ```="" ##="" polarization="" between="" education="" groups="" the="" figure="" below="" reports="" mean="" wages="" by="" education="" group="" over="" time,="" plotted="" separately="" for="" men="" and="" women.="" replicate="" this="" figure="" using="" the="" `morg`="" data="" frame.="" the="" wage="" data="" is="" in="" constant="" 2000="" dollars.="" for="" lower="" education="" groups="" (those="" without="" a="" university="" degree),="" real="" wages="" have="" actually="" fallen="" since="" 1979.="" for="" higher="" education="" groups,="" real="" wages="" have="" grown="" --="" particularly="" for="" advanced="" degree="" holders.="" overall,="" wage="" inequality="" between="" those="" with="" and="" without="" university="" education="" has="" grown="" sharply="" in="" the="" past="" three="" decades.="" it="" is="" notable="" that="" for="" those="" with="" a="" university="" degree="" (16="" years="" of="" education)="" (but="" not="" an="" advanced="" degree,="" ma="" or="" greater),="" wages="" have="" been="" fairly="" stagnant="" since="" the="" year="" 2000,="" while="" advanced="" degree="" holders="" have="" seen="" modest="" wage="" growth.="" ![](http://ben-sand.github.io/files/educ_wages.png)="" ```{r}="" #="" replicate="" figure="" here="" ```="" ##="" inequality="" within="" education="" groups="" the="" above="" figure="" captures="" mean="" wage="" differences="" **between**="" wage="" groups.="" another="" form="" of="" inequality="" is="" **within**="" education="" groups.="" that="" is,="" if="" we="" look="" at="" one="" particular="" group="" (say="" high="" school="" graduates),="" have="" wage="" differences="" grown="" over="" time?="" one="" way="" to="" look="" at="" this="" is="" to="" examine="" the="" [interquartile="" range](interquartile="" range)="" of="" wages="" within="" education="" group.="" we="" can="" visualize="" this="" using="" a="" `geom_ribbon`="" plot.="" 1.="" create="" a="" data="" frame="" called="" `fig`="" from="" `morg`="" 1.="" filter="" for="" only="" `men`.="" 2.="" group="" data="" by="" `year`="" and="" `highest.degree`,="" 3.="" use="" the="" function="" `quantile`="" to="" calculate="" the="" 25th,="" 75th,="" and="" 50th="" (median)="" wage="" for="" each="" group="" using="" `summarise()`="" 4.="" plot="" using="" the="" `geom_ribbon`="" 5.="" overly="" a="" `geom_line`="" showing="" the="" median="" age.="" comment="" on="" how="" the="" interquartile="" range="" has="" changed="" over="" time="" for="" the="" various="" education="" groups.="" ```{r,="" eval="F}" #="" fig="" data="" fig=""><- morg="" %="">% filter(...) %>% group_by(..., ...) %>% summarize(p10 = quantile(..., probs = .25, na.rm = T), p90 = quantile(..., probs = .75, na.rm = T), p50 = quantile(..., probs = .5, na.rm = T)) ``` ```{r, eval = F} # plot ggplot(...) + geom_ribbon(aes(ymax = p90, ymin=p10, x = year), alpha = .5) + geom_line(aes(y = ..., x = year)) + facet_wrap(~highest.degree) ``` ## Job polarization Job polarization refers to how the occupation structure has changed over time. To capture this, we need to get the proportion of employment in each occupation group (`occ_cat`) by gender and year. This requires two calls of `group_by()`. Edit the code below to construct a data frame called `fig` with mean occupation wages (`wage`) and employment share (`share`). Describe what each step
Answered 1 days AfterJan 26, 2021

Answer To: --- title: "Assignment 1" author: "Econ 4210" date: "20/01/2021" output: html_document --- ```{r...

Hemanth answered on Jan 28 2021
136 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here