1 Basic information

This is a list of 6 exercises for the Applied Quantitative Methods with R labs. You can solve these exercises

using base R functionalities or functions from the tidyverse (e.g. dplyr ) package. Solutions should be

send via moodle platform. Outputs are presented in html tables but only for comparison purposes. You do

not need to create html tables. Note that solving some of these exercises requires going through help

pages or looking for an appropriate function in the packages documentation.

Deadline to send solutions is the 9th of January 2023.

If you have questions do not hesitate to contact us via email.

2 Exercise 1 (1 pt)

The sum of the squares of the first ten natural numbers is,

The square of the sum of the first ten natural numbers is,

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the

sum is .

Find the difference between the sum of the squares of the first one hundred natural numbers and the

square of the sum.

Result: -25164150 .

3 Exercise 2 (1 pt)

Write an R program to create a data.frame which contain the following details

employee salary

Jane B 1000

David G 2500

Emilo A 1500

Assignments for extra 10 pts

Maciej Beręsewicz, Tomasz Klimanek, Marcin Szymkowiak

AUTHOR

12 + 22+. . . +102 = 385

(1 + 2+. . . +10)2 = 552 = 3025

385 − 3025 = −2640

employee salary

Janet F 3000

George H 680

and display summary of the data.

4 Exercise 3 (1 pt)

Download this dataset. The dataset is about the number of foreigners insured in Poland according to the

ZUS data. It contains the following columns:

kwartal – quarter (format: YYYYQQ, i.e. 2021Q1 refers to 1 quarter of 2021)

obywatelstwo – citizenship (in Polish)

wiek – age group (levels: ogol, 19, 20-24, 25-29, 30-34, 35-39, 40-44, 45-49, 50-54, 55-59, 60-

64, 60+, 65 , where ogol refers to total ),

plec – sex (levels: ogol, kob, mez , where ogol refers to total , kob to females and mez to males ),

ubezp – the number of insured people.

Your task in this assignment consists of two steps:

1. read the data using appropriate function from the readr package or base R (0.5 pt),

2. rename the columns using the following rules (0.5 pt),

kwartal to quarter ,

obywatelstwo to citizenship ,

wiek to age ,

plec to sex ,

ubezp to count .

The expected result is presented below.

quarter citizenship age sex count

2019Q1 ALBAŃSKIE ogol ogol 369

2019Q1 ALGIERSKIE ogol ogol 592

2019Q1 AMERYKAŃSKIE ogol ogol 1792

2019Q1 ANDORSKIE ogol ogol 6

2019Q1 ANGOLSKIE ogol ogol 142

2019Q1 ARGENTYŃSKIE ogol ogol 177

https://gist.githubusercontent.com/BERENZ/788573cbd805b0a1cbfd8d4597118796/raw/33b031e8f6e9e11859f0c50115488bebc58edc54/zus-2019-2022-zdr.csv

https://psz.zus.pl/

5 Exercise 4 (2 pt)

Create the following data.frame containing information about the overall number of foreigners in Poland

according to ZUS data. Column quarter refers to the quarter column and Freq is based on the count

column.

quarter Freq

2019Q1 643188

2019Q2 677035

2019Q3 697824

2019Q4 650889

2020Q1 697762

2020Q2 638629

2020Q3 724208

2020Q4 764181

2021Q1 807963

2021Q2 862307

2021Q3 889442

2021Q4 922114

2022Q1 991946

2022Q2 1081686

2022Q3 1116831

6 Exercise 5 (2 pt)

Based on the above data prepare the information about Ukraine (UKRAIŃSKIE ) and Belgium (BELGIJSKIE )

citizens in age between 40 and 64. After the aggregation change UKRAIŃSKIE to Ukraine and BELGIJSKIE

to Belgium . The expected output is given in the following table

citizenship

quarter Belgium Ukraine

2019Q1 245 140360

2019Q2 252 151400

2019Q3 251 157233

2019Q4 257 151981

2020Q1 255 158225

2020Q2 255 144752

2020Q3 247 169625

2020Q4 248 179599

2020Q4 248 179599

2021Q1 256 191868

2021Q2 264 205799

2021Q3 259 211859

2021Q4 265 217916

2022Q1 271 236640

2022Q2 282 262555

2022Q3 288 270231

7 Exercise 6 (3 pt)

Calculate the share of Ukrainians (UKRAIŃSKIE ) in all insured foreigners in Poland in the study period.

Expected results are presented below.

ukraine

quarter Rest Ukrainians

2019Q1 0.2688545 0.7311455

2019Q2 0.2638593 0.7361407

2019Q3 0.2624071 0.7375929

2019Q4 0.2639098 0.7360902

2020Q1 0.2819228 0.7180772

2020Q2 0.2987807 0.7012193

2020Q3 0.2774852 0.7225148

2020Q4 0.2785937 0.7214063

2021Q1 0.2759693 0.7240307

2021Q2 0.2747038 0.7252962

2021Q3 0.2822500 0.7177500

2021Q4 0.2946707 0.7053293

2022Q1 0.2933688 0.7066312

2022Q2 0.2863419 0.7136581

2022Q3 0.2940884 0.7059116