# What statistical method to use for binary independent variable and continuous dependent variable

I have a dataset that has columns item, week, and units sold. I have another dataset that has columns group, week, and flag.

The weeks for both datasets lie in the same range. Units sold is continuous variable, and flag is a binary variable.

For each item/group combo, I would like to see if there is a relationship between units sold and flag. Specifically, if flag is 1, then units sold increases. I would also like the output to be numerical so that I can rank which item/group combos are most significant.

I cannot make the assumption that units sold is normally distributed, for any of the items, if that matters.

Lastly, there is about a 100 million combinations of item/groups, so the method must be computationally efficient. I have tried a simple linear regression, but that would take approximately 80 hours. Something under 5 hours is much better.

What statistical methods are available to me? Bonus points if the method already has a package in python or R.

• Is group a set of all items that are all assigned to have flag = 1 in a given week? Are groups stable over time? Commented Jul 31 at 19:44
• @dimitriy Yes, a group represents a set of items that have flag = 1 in a given week. Group takes the form of an ID. I am unsure what you mean by stable? Commented Jul 31 at 19:54
• Stable means the items that make up a group stay constant over time as you toggle the flag. In other words, the flag experience is assigned at group level rather than item level. Commented Jul 31 at 20:18
• @dimitriy Yes, the items within the group are stable. Commented Jul 31 at 20:37

I would start with a Poison panel model with units sold as the outcome on a constant, a binary indicator $$\mathbf{I}(\mathtt{flag}_{iw} = 1)$$, plus week and item fixed effects. The exponentiated coefficient on the flag, $$\exp(\hat \beta)$$ will give you a multiplicative effect on sales. Ideally, $$\exp(\hat \beta) >> 1$$. You can do a formal hypothesis test of this that returns a p-value and/or calculate a confidence interval (which should lie entirely above 1).

The expected value of item $$i$$ in week $$w$$

\begin{aligned} \mathbb{E}[\mathtt{sales}_{iw} \mid \mathtt{week, flag, item}] &= \exp \left( \alpha + \beta \cdot \mathbf{I}(\mathtt{flag}_{iw} = 1) + \gamma_w + \nu_i \right) \\ &=\underbrace{\exp \left( \alpha + \gamma_w + \nu_i \right)}_{\text{baseline sales}} \cdot \underbrace{\exp \left(\beta \cdot \mathbf{I}(\mathtt{flag}_{iw} = 1) \right)}_{\text{flag-on factor}} \end{aligned}

When the flag is off, then $$\exp(0)=1$$, so the expected sales are just the baseline for product $$i$$ in week $$w$$.

The $$\nu$$s, $$\gamma$$s, and $$\alpha$$ are nuisance parameters and are integrated out using a computational trick. This should speed things up considerably since you no longer need to estimate them. You could also include other variables in the baseline, like holidays.

The data should be in a long format, where each row contains sales for an item in a given week, including zeros if there are no sales.

The standard errors should be clustered by group group (since that is the level at which treatment is assigned). This will also relax the restrictive Poisson mean = variance assumption that is always violated by sales data.

This assumes that flags are toggled on at random. If that's not the case, then something more complicated may be needed to estimate the causal effect.

You can do this in R with fixest. You can do this in Python with pyfixest. In Stata, use ppmlhdfe or the built-in xtpoisson. There are probably other packages/functions that I left out.