Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generating new variable that replicates one of two string variables, decided by a dummy variable

    Hi all

    I want to generate a new variable (loc) that takes on its value from one of two str3 variables (tm or opp). This will be conditional on a dummy variable (home). So if home=1 take on the value of tm, otherwise, opp. I have scoured the internet and the Stata manual but I don't think my search terms are optimised to help me find what I'm looking for. Apologies if this has already been answered.

    Any help would be greatly appreciated.
    Last edited by Ashwin Sivakumar; 13 Sep 2022, 08:15. Reason: vocabulary

  • #2
    Code:
    gen loc = cond(home == 1, tm, opp)

    See e.g. https://www.stata-journal.com/articl...article=pr0016 for more discussion.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Code:
      gen loc = cond(home == 1, tm, opp)

      See e.g. https://www.stata-journal.com/articl...article=pr0016 for more discussion.
      Thank you Nick! Both for the command and the link. Have a good day.

      Comment

      Working...
      X