Friday, June 18, 2021

Some of the useful codes in R (Applied Econometrics with R)

  ■ Some codes in R


Note: Dep var = Dependent Variable.

           Ind var = Independent Variable.

           Var 1 = Variable 1

           Var 2 = Variable 2

a) Taking log values

lvar1 <- log(var1, base = 10)


b) Correlation Test

#install.packages (corTest)

library (corTest)

cor.test(var1, var2)


c) Unit Roots Test (without deseaonalisation)

# install.packages(fUnitRoots)

library(fUnitRoots)


d) Testing Unit Root at Level (ADF)

adfTest (lvar1, lags = 0, type = "c")


e) Taking 1st difference

d.var1 <-diff (var1)


f) Lag selection criteria

#install.packages (vars)

library (vars)

Say, 

kk <-cbind (lvar1, lvar2, ... lvarn)

VARselect (kk) $selection


g) Co Integration  (Johannessen)

Say,

JC1 <- ca.jo (kk, type = "trace", ecdet = "none", K =3)


h) Eigen Value Stat

JC1 <- ca.jo (kk, type = "eigen", ecdet = "none", k = 3)

i) VECM (in p - 1 lags)

Say, 

model1 = VECM (data.frame (vars), lag = n, r = m, estim = "ML")

where, r = no. of co integrating relationship (will discuss later)


j) Impulse Response Function

plot (irf (model1, n.ahead=10))

for 10 periods.


k) Multicollinearity in R

Packages are - car, faraway, VIF, fmsb, HH.

Say, 

#install.packages (faraway)

library (faraway)

model1 = lm (depvar~ind vars)

faraway : : vif (model1)

The result obtained should be less than 5.


l) Serial Correlation in R

Box.Test (var, lag = n, type = "Ljung-Box")

Box.Test (var, lag = n, type = "Box-Pierce")

Serial correlation if exist we can make the model into GARCH.


m) Heteroscedasticity in R

#install.packages (lmtest)

model1 = lm (var1~ var2)

bp test (model1) Breush Pagan test


n) Normality Test

Shapiro - Wilk test

Say a hypothetical test

c < - LC $ variable [1:n]

shapiro.test (c)

If the result p value is more than .05 then the data is normally distributed.


o) Ramsey Test

#install.packages (lmtest)

library (lmtest)

model1 = lm (var 1 ~ var 2)

resettest (model1)

Let's see the results, Ho: There's linearity in model.

If the p value is more than .05 then our null hypothesis is accepted then linearity in the model.


To be contd...

Aditya Pokhrel 

P.S Comments are lauded



Saturday, June 12, 2021

Stochastic and Deterministic trend using R (Applied Econometrics)

Stochastic and Deterministic trend using R

Let’s say that there are two variables. The share price of Nepal Lever Ltd and there’s a NEPSE index. We will now identify whether the NEPSE index has a stochastic or a deterministic trend.

For this we have to install the packages and import the data as in .csv files (this data import is skipped over here).

For this: tseries would be the package.

Now, in R studio, it is

library(tseries)

attach(NepaLever)

nepse = NepaLever $ NEPSEINDEX

Now it is to be noted that if the time series has trend then its parameters may not be stable and remain same in the future and our forecast may not be correct.

Let’s plot.

plot.ts(nepse)

See the figure. If the trending variable change in an uncertain amount in each period (vt) say, then it is known as the stochastic trend.

Now, let’s see for deterministic trend

Say, there is the data named as “datsalesyear”

Now, In R,

library(tseries)

attach(datsalesyear)

plot.ts(datsalesyear)

After this, view the graph. If the change is constant then there’s a deterministic trend.

SOLUTION: If the series has a deterministic trend the solution is de trending.

         If the series has a stochastic trend the solution is re trending.

Note: More will be discussed on re trending and de trending on upcoming blogs.


Thank You

P.S Comments are lauded.

Aditya Pokhrel

Thursday, June 10, 2021

What does GEPR (June 2021) highlight ? Here you go. (International Economics).

# Global Economic Prospects Report – June, 2021

 

1)      Global Economy is expected to expand by 5.6 % in the year 2021 (this is said to be the fastest post recession expansion in 80 years).

 

2)      The global output is expected to be below 2 % if it is compared with the pre-pandemic projections for the end of the year 2021.

 

3)      The economic growth of the U.S is expected to rise by 6.8 % in the year 2021 (this is due to the easing of the pandemic restrictions and large fiscal support).

 

4)      The economic growth of China is expected to rise by 8.5 % in the year 202 (due to the release of the pent-up demand).

Note: Pent up Demand is the condition where the demand for a product/service is unusually strong.

 

5)      Emerging markets and developing economies are expected to grow at 6 % in a year (due to the higher demand and elevated commodity prices).

 

6)      The economic growth of the East Asia and Pacific is projected to grow by 7.7 % in 2021 (5.3 % in 2022).

 

7)      The economic growth of the Europe and Central Asia is projected to grow by 3.9 % in 2021 (3.9 % in 2022).

 

8)      The economic growth of the Latin America and Caribbean is projected to grow by 5.2 % in 2021 (2.9 % in 2022).

 

9)      The economic growth of the Middle East and North Africa is projected to grow by 2.4 % in 2021 (3.5 % in 2022).

 

10)  The economic growth of the South Asia is projected to grow by 6.8 % in 2021 (6.8 % in 2022).

 

11)  The economic growth of the Sub Saharan Africa is projected to grow by 2.8 % in 2021 (3.3 % in 2022).

 

12)  The Per Capita Income of the many emerging and developing economies is also expected to remain below the pre-pandemic levels and the losses are expected to worsen the deprivations associated with health, education and living standards.

 

13)  The economic growth of the low-income economies in the year 2021 is expected to grow by a 2.9 % (2021) and 4.7 % (2022) (the growth in 2021 is said to be slowest in the past 20 years, partly reflecting the very slow pace of the vaccination).

 

14)  Trade costs will remain almost one-half higher in the emerging markets and developing economies than in the advanced economies, in a large part due to the higher shipping and logistics costs.

 

15)  The higher global inflation may complicate the policy choices of the emerging markets and the developing economies in up coming months as some of these economies still rely upon the expansionary support measures to ensure a durable recovery.

 

16)   The challenges related to the food insecurity in the low-income countries can rise due to the rising food prices and accelerating the aggregate inflation in the year 2021.

 

Thank You

Aditya Pokhrel

Regression Discontinuity - How to determine whether it is Sharp or Fuzzy RD ? Simplest Look.           Regression discontinuity design is ga...