Why is the explanatory variable non-stochastic or fixed in repeated samples? I am studying econometrics. I have been learning about deriving the variance for the OLS slope statistic in a simple linear regression model.
Why is the explanatory variable considered to be non-stochastic or fixed in repeated samples?
This idea makes no intuitive sense to me because I thought that in econometrics we only deal with observational data, and hence we cannot control what the values for the explanatory variable will be.
 A: The main reason is simply for teaching purposes: Assuming fixed explanatory variables ensures that the error term is independent of the (deterministic) variables, $E(u|X) = 0$ holds by definition, see also here. Sometimes you started with fixed / deterministic explanatory variables in a first undergraduate course to explain the basic ideas and algebra. Then proceed with stochastic variables to make clear that in the real world correlation and causality are not always the same.
Wooldridge describes this in his (advanced) textbook Econometric Analysis of Cross Section and Panel Data as follows:

In a first course in econometrics, the method of ordinary least squares (OLS) and
its extensions are usually learned under the fixed regressor assumption. This is appropriate for understanding the mechanics of least squares and for gaining experience
with statistical derivations. Unfortunately, reliance on fixed regressors or, more generally, fixed ‘‘exogenous’’ variables, can have unintended consequences, especially in
more advanced settings. [...] This is not just a technical point: estimation methods that are consistent under the fixed regressor assumption, such as generalized least squares, are no longer consistent when the fixed
regressor assumption is relaxed in interesting ways.

A: I assume this is a regression model. The main reason is inferential, the explanatory variable(s) are treated as fixed for purposes of inference. The regression model $Y= X\beta + \epsilon$ is a model for the conditional expectation of $Y$ given $X$: $\DeclareMathOperator{\E}{\mathbb{E}} \E\left\{ Y | X=x\right\} = x^T \beta$ which is assumed to hold whichever value of $x$, so variation in $x$ has no role in describing that relation.
For more details see What is the difference between conditioning on regressors vs. treating them as fixed?
