When to use instrumental variables in a panel regression R I'm doing panel regression analysis using plm package.
I would like to know if there is a way to understand when it's necessary to use instrumental variables.  Are there any tests to understand it, or something like that?
I hope this question is appropriate for this forum. Thanks in advance.
 A: This question is best answered from the viewpoint of causal graphs. Suppose we have this causal graph:

Here the $U_X, U_Y,$ and $U_Z$ are exogenous variables, and we are interested in the true causal effect $\alpha$ of $X$ on $Y$. Unfortunately, the dashed line represents an unobserved common cause of $X$ and $Y$ and hence a confounding situation. Pearl writes:

Since it hasn't been measured, we can't condition on it, so $X$ and $Y$ will always be dependent through it. In this particular case, we may use an instrumental variable to determine the direct effect. A variable is called an "instrument" if it is $d$-separated from $Y$ in $G_{\alpha}$ and, it is $d$-connected to $X.$ - Causal Inference in Statistics, A Primer, by Pearl, Glymour, and Jewell, p. 86.

It is this sort of situation where you should use an instrumental variable, and perhaps do the 2-stage least squares approach.
A: I'll start by saying I don't think it is ever "necessary" to do IV. Typically, if you want the correlation between two variables, straight regression is fine.
However, if you want to learn about a causal relationship between two variables, IV is a valuable tool. On top of standard regression, IV layers in two more assumptions.
The first assumption, known as relevance, is that you have a variable $Z$, which affects  $X$. This is important. There is a whole literature on "weak IV" discussing the problems that can arise when you try to do instrumental variables with a variable $Z$ which is just noise. Broadly, in terms of your question about tests that can be performed, this is where we can make progress. The rule of thumb is that if the standard F-test for your first stage regression comfortably rejects the Null, then this assumption is met. That rule of thumb is by no means perfect, but broadly, the notion that we can tell if there is a relationship is widely agreed on.
The second assumption is what I call the exclusion assumption (naming varies). The exclusion assumption asserts that $Z$ only affects $Y$ through its effects on $X$. This is in principal an untestable assumption -- though we can make arguments for and against it. This assumption is why many IV analyses include a lengthy discussion of the validity of the instrument in question. Describing how it could not easily affect $Y$ other than through $X$. Some treatments of IV will discuss how RCTs can be framed as IV, where the treatment decision predicts treatment, but can't affect outcomes in other ways.
Given these two assumptions, standard IV approaches (like 2SLS), can allow us to establish a causal relationship between $X$ and $Y$ because $Z$ can shift $X$, and thus possibly $Y$, without shifting $Y$ in any other way. Thus if a regression of $Y$ on $Z$ shows a relationship between the two, there must be a causal relationship between $X$ and $Y$.
A: Thanks to both of you for the clarifications. However it is not clear to me how to do it in practice, in particular working with the panel regressions in r. Using the plm package I can make pooling, within and random models and I can insert the instrumental variables through the symbol | however I don't understand how to decide if and what to insert as IV. If I don't ask much, could you illustrate some practical examples with R, so I can clarify my doubts?
