Announcement

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

  • Creating multiple variables at once

    I might be losing my mind, but I thought I once ran across a component of Stata syntax (command, extension, option, etc.) that could do the following using only one line of code:

    In this scenario, I have the following:
    1. a string grouping variable (called group) that takes two possible values: a or b
    2. a numeric outcome variable (called score) that takes values 1 to 100
    If the syntax I'm thinking of actually exists, it could generate two new variables at once:
    1. score_a would take values of score when group==yes
    2. score_b would take values of score when group==no
    Does this sound remotely familiar to anyone? Or am I inventing this? After significant web searching this morning I haven't been able to find anything like what I have in mind. But I'd swear I encountered something like this at some point in the past.

    If anyone could put me out of my misery one way or another, I'd be obliged.



  • #2
    you want the mean?

    the data is there already, so not obvious what you're after.

    just to create new variables,

    g score_a = score if group=="a"
    g score_b = score if group=="b"

    if you want them to have 0 values rather than missing, you could use cond() or replace if ==.

    Comment


    • #3
      I want the original raw values from the score column, not a calculated value derived from them. Your suggested two lines of code do what I want, but I'm wondering if there is a Stata command that achieves the same purpose using only one line.

      Comment


      • #4

        Code:
        help separate
        seems to be what you're seeking.

        Comment


        • #5
          That's it! Thanks Nick!

          I should have asked here much earlier; that command really resists being discovered through Googling.

          Comment


          • #6
            As the original author, the command name seems natural to me.

            split was taken at about the same time for something different (but not completely different).

            Comment

            Working...
            X