Ekonometrika

Task 1


Kontak : \(\downarrow\)
Email
Instagram https://www.instagram.com/saram.05/
RPubs https://rpubs.com/sausanramadhani/
LinkedIn https://id.linkedin.com/in/sausan-ramadhani-318532263

1. GDP & Unemployment rate

Let’s consider a scenario where we want to analyze the relationship between a country’s GDP (Gross Domestic Product) and its unemployment rate. The hypothesis is that higher GDP leads to lower unemployment rates due to increased economic activity and job creation. First, we’ll generate a simulated dataset with two variables: GDP and unemployment rate. We’ll assume a linear relationship between the two variables with some random noise.

set.seed(123)  # For reproducibility

# Generate simulated data
n <- 10000  # Number of observations
gdp <- rnorm(n, mean=1000, sd=200)  # Simulated GDP data
unemployment <- 10 - 0.05 * gdp + rnorm(n, mean=0, sd=2)   #Simulated umemployement data

# Creat a data frame
data <- data.frame(GDP=gdp, Unemployment=unemployment)
head(data)

Explore the data visually

Explore the data visually to understand the relationship between GDP and unemployment rate

library(ggplot2)

ggplot(data, aes(x=gdp, y=unemployment)) +
  geom_point(color = "#77B0AA", alpha = 0.6) +
  geom_smooth(method = "lm", se = FALSE, color = "#1A4D2E") +
  labs(little = "The Relationship between GDP and unemployment rate",
       x = "GDP",
       y = "Unemployment Rate") +
  theme_minimal() +
  theme(plot.title = element_text(size = 16, hjust = 0.5),
        axis.title = element_text(size = 14))

The graph depicting the relationship between the value of GDP and the unemployment rate is interesting as it shows a consistent pattern:

  • The higher a country’s GDP value, the lower its unemployment rate. This confirms the concept of a negative relationship between the two variables.
  • Data that displays a pattern like this usually indicates a linear relationship between two variables. By understanding this pattern, we can move on to the next step.

Perform simple linear regression

Perform simple linear regression to quantify the relationship between GDP and unemployment rate

lm_model <- lm(unemployment ~ gdp, data)
summary(lm_model)
## 
## Call:
## lm(formula = unemployment ~ gdp, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.9652 -1.3378 -0.0148  1.3617  7.5393 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  9.9214218  0.1022358   97.04   <2e-16 ***
## gdp         -0.0499396  0.0001003 -497.89   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.003 on 9998 degrees of freedom
## Multiple R-squared:  0.9612, Adjusted R-squared:  0.9612 
## F-statistic: 2.479e+05 on 1 and 9998 DF,  p-value: < 2.2e-16

Based on the above results, several values are obtained that can help determine the relationship between GDP and the Unemployment Rate:

  • The Residual Standard Error is about 2003 units of the true value.
  • The multiple R-squared is 0.9612, which means that the model is able to explain about 96% of the variability in the unemployment rate.
  • P-Value < 2.2e-16, which means the overall model is highly significant.

Interpret the relationship

Interpret the relationship between GDP and unemployment rate :

The regression model shows that there is a significant relationship between GDP and the unemployment rate. Each one-unit increase in GDP corresponds to a decrease of about 0.05 units in the unemployment rate (in units used).

2. GDP Growth Rate and Investment Rate

The objective of this study case is to demonstrate how simple linear regression can be used to analyze economic data and make predictions based on the relationship between two variables. Lets generate data for GDP growth rate (gdp_growth) and investment rate (investment_rate) for a fictional country over a period of 10 years.

# Set seed for reproducibility
set.seed(123)

# Generate data
years <- 1:10
investment_rate <- rnorm(10, mean = 20, sd = 5)
gdp_growth <- 3 + 0.8 * investment_rate + rnorm(10, mean = 0, sd = 1)

# Create a data frame
data_2 <- data.frame(years, investment_rate, gdp_growth)
data_2

Perform simple linear regression

Perform simple linear regression analysis to understand the relationship between GDP growth rate and investment rate

ggplot(data_2, aes(x=investment_rate, y=gdp_growth)) +
  geom_point(color = "#51829B", alpha = 0.6) +
  geom_smooth(method = "lm", se = FALSE, color = "#803D3B") +
  labs(little = "The Relationship between GDP and unemployment rate",
       x = "GDP",
       y = "Unemployment Rate") +
  theme_minimal() +
  theme(plot.title = element_text(size = 16, hjust = 0.5),
        axis.title = element_text(size = 14))

The graph shows that the data has a positive linear pattern.

lm_model_2 <- lm(gdp_growth ~ investment_rate, data = data_2)
summary(lm_model_2)
## 
## Call:
## lm(formula = gdp_growth ~ investment_rate, data = data_2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.33303 -0.64421 -0.02448  0.49596  1.41472 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      0.64706    1.31108   0.494    0.635    
## investment_rate  0.92573    0.06282  14.736 4.42e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8988 on 8 degrees of freedom
## Multiple R-squared:  0.9645, Adjusted R-squared:   0.96 
## F-statistic: 217.1 on 1 and 8 DF,  p-value: 4.423e-07

The average model prediction from this data differs by about 0.8988 units from the actual value. The value of about 0.96 (multiple r-squared) indicates that our model is able to explain about 96% of the variability in GDP growth. The very small p-value (4.423e-07) indicates that the overall model is highly statistically significant.

Make predictions

new_investment <- data.frame(investment_rate = c(10,20,30))
predicted_gdp_growth <- predict(lm_model_2, newdata = new_investment)
gdp <- data.frame(investment_rate = new_investment$investment_rate, predicted_gdp_growth)
gdp

Gained insights

Gained insights into how changes in investment may influence economic growth :

The data shows the predicted GDP growth based on the level of investment. From the given data, there are three observations:

  1. When the investment rate is 10, the model predicts GDP growth of 9.904386.
  2. When the investment rate is 20, the model predicts GDP growth of 19.161708.
  3. When the investment level is 30, the model predicts GDP growth of 28.419030.

This result shows that, based on the regression model developed earlier, there is a positive relationship between the level of investment and GDP growth. The higher the investment level, the higher the GDP growth prediction generated by the model. This is consistent with the assumption that higher investment can increase economic growth.