title: Checking a panel unit root test in R done manually
body: <p>I have spent much time looking for a special package that could run the Pesaran(2007) unit root test (which assumes cross-sectional dependence unlike most others) and I have found none. So, I decided to do it manually; however, I don't know where I'm going wrong, because my results are very different from Microsoft Excel's results (in which it is done very easily).</p>
  
  <p>My data frame is made up of 22 countries with 506 observations of daily price indices. Following is the model to run using the Pesaran(2007) unit root test:</p>
  
  <p>(i) With an intercept only</p>
  
  <p><img src="https://i.stack.imgur.com/pLHKa.png" alt="enter image description here"></p>
  
  <p>where $\overline{Y}$ is the cross-section average of the observations across countries at each time $t$ and $b$ is the coefficient of interest to us because it will allow us to compute the ADF test statistic and then determine whether the process is stationary or not.</p>
  
  <p>I constructed each of these variables in the following way:</p>
  
  <p>(Delta)Y(t)</p>
  
  <pre><code>dif.yt = diff(yt) 
  ## yt is the object containing all the observations for a specific country 
  ## (e.g. Australia)
  </code></pre>
  
  <p>Y(t-1)</p>
  
  <pre><code>yt.lag.1 = lag(yt, -1)
  </code></pre>
  
  <p>Y(bar)(t-1)</p>
  
  <pre><code>ybar.lag.1 = lag(c(rowMeans(x)), -1) 
  ## x is the object containing my entire data frame
  </code></pre>
  
  <p>(Delta)Y(bar)(t-1)</p>
  
  <pre><code>dif.ybar.lag.1 = diff(ybar.lag.1)
  </code></pre>
  
  <p>(Delta)Y(bar)(t-2)</p>
  
  <pre><code>dif.ybar.lag.2 = diff(lag(c(rowMeans(x)), -2))
  </code></pre>
  
  <p>(Delta)Y(t-1)</p>
  
  <pre><code>dif.yt.lag.1 = diff(yt.lag.1)
  </code></pre>
  
  <p>(Delta)Y(t-2)</p>
  
  <pre><code>dif.yt.lag.2 = diff(lag(yt, -2)
  </code></pre>
  
  <p>After constructing each variable individually, I then run the linear regression</p>
  
  <pre><code>reg = lm(dif.yt ~ yt.lag.1[-1] + ybar.lag.1[-1] + dif.ybar.lag.1 + 
                    dif.ybar.lag.2 + dif.yt.lag.1 + dif.yt.lag.2)
  summary(reg)
  </code></pre>
  
  <p>It is obvious that the explanatory variables in my regression equation differ in length, so I'd like to know whether there is a way in R to make all the variables of equal length (perhaps with a function).</p>
  
  <p>Also, I'd like to know whether the procedure I used was correct and if there are more optimal ways.</p>