title: Replace values in r using case_when
body: <p>I'm trying to replicate some Stata code in r. In my df, there is a variable &quot;time&quot; and one &quot;exposure&quot; (both numeric, so with values like 1,2,3 etc.</p>
  <p>This is what the original Stata code looks like:</p>
  <pre><code>replace time = (time - 31) if exposure == 0
  </code></pre>
  <p>And this is what I tried:</p>
  <pre><code>recoded_df &lt;- recoded_df %&gt;% mutate(time = case_when(exposure == 0 ~ (time - 31))
  </code></pre>
  <p>I get the error that there is an &quot;unexpected symbol&quot; in the code. But I have no idea what I am doing wrong.</p>