title: Conditional Regression Model in Python
body: <p>In python, I have created a regression model by using this code: </p>
  
  <pre><code>import statsmodels.formula.api as sm
  df = pd.DataFrame({"A": data['dur'], "B": data['agreement'], "C": data['vidPersonIdeoDiff'], "D": data['opinionChange'],  "G": data['fake']})
  result = sm.ols(formula="A ~ B + C + D + G", data=df).fit()
  print(result.params)
  
  print(result.summary())
  </code></pre>
  
  <p>Now, I am interested in adding a condition or 'if-statement' to the same regression. How would I run it but only for certain groups, such as if age is &lt; 36? In Stata, the equivalent would be:</p>
  
  <pre><code>reg dur agreement vidPersonIdeoDiff opinionChange fake if age &lt; 36
  </code></pre>
  
  <p>Any idea how I can replicate that stata line in python? It'd be especially helpful if the solution is congruent to the statsmodels.formula.api module I've been using. Thanks!</p>