# abond command
In this tutorial, we illustrate the functions of pydynpd with examples. The first data set is one from Arellano and Bond (1991). It is an unblanced panel with 140 firms over 9 years (1976-1984). You can download the data (data.csv) from the /benchmark/code folder. We first consider the following basic model:

$$
\begin{align}
n_{i,t}=\alpha_1n_{i,t-1}+\alpha_2n_{i,t-2}+\beta_1w_{i,t}+\gamma_1k_{i,t}+u_{i}+\epsilon_{i,t}
\end{align}
$$

In the model above, variables $n$, $w$, and $k$ are the natural logarithm of employment, wage, and capital respectively. $u_{i}$ is unobserved fixed effect and $\epsilon_{i,t}$ is idiosyncraic error. 

To estimate the model, we first load data to Pandas data frame:




```python
import pandas as pd
from  pydynpd import regression
df = pd.read_csv("test_data.csv")
```

Then we construct command string to describe the model. A command string has two or three parts, which are separated by |.
Part 1 is a list starting with the dependent variable, and followed by independent variables except time dummies. Given the model, part 1 is:

```
n L1.n L2.n w k
```
In the command above, L is the lag operator as in L1.n (i.e., $n_{i,t-1}$) or L2.n for 2 lags of n (i.e., $n_{i,t-2}$). 

Part 2 indicates how instruments are created. First, suppose we want to use the second and third lags of dependent variable n (i.e., L2.n and L3.n) as instruments, then we include the following GMM list:

```
GMM(n, 2:3)
```
Next, suppose we believe that variable w is a predetermined variable and use its first and deeper lags (i.e., L1.w, L2.w, ...) as instruments. Then we include a second GMM list:

```
GMM(w, 1:.)
```
The dot (.) above means there is no restriction regarding the maximum lag of $w$. In other words, we use all available lags.
Next, suppose variable $k$ is a strictly exogenous variable. So, we use IV() list:

```
IV(k)
```
This tells pydynpd to use variable $k$ itself as instrument.
Finally, we put all GMM and IV lists together to form part 2:
```
GMM(n, 2:3) GMM(w, 1:.) IV(k)
```

Suppose our command just has the two parts above, then we combine the two parts together:


```python
command_str='n L1.n L2.n w k  | GMM(n, 2:3) GMM(w, 1:.) IV(k)'

```

Finally, we use abond function to estimate our model. Note that three parameters should be provided. The first one is the command string discussed above. The second one is the data, and the third one is a list of two variables that indentify individual firm and year respectively. 


```python
mydpd = regression.abond(command_str, df, ['id', 'year'])
```

bd5f5e5b722bd2d2a42829eaa7b8e290f11c4013
ipynb
Jupyter Notebook
vignettes/.ipynb_checkpoints/Tutorial-checkpoint.ipynb
dazhwu/pydynpd
910563c28000e6200c11beddd6aa80b9602c5315
MIT
2022-03-15T16:51:02.000Z
2022-03-27T15:22:44.000Z
vignettes/.ipynb_checkpoints/Tutorial-checkpoint.ipynb
dazhwu/pydynpd
910563c28000e6200c11beddd6aa80b9602c5315
MIT
vignettes/.ipynb_checkpoints/Tutorial-checkpoint.ipynb
dazhwu/pydynpd
910563c28000e6200c11beddd6aa80b9602c5315
MIT
Qwen/Qwen-72B
1. YES
2. YES