Forum Discussion

erchs's avatar
erchs
Frequent Visitor
9 years ago
Solved

Generating numbers conditional on another column

My dataset contains a variable (X) with two categories, A and B.  The data looks like this:   X A A A A B B B B   I would like to generate a new variable, Y, such that there will be a ce...
  • Anonymous's avatar
    Anonymous
    9 years ago

    Hi erchs,

     

    You can add a calculated column with RANDBETWEEN and SWITCH function to calculate the result:

     

    Y = SWITCH([X],"A",SWITCH(RANDBETWEEN(0,1),0,1,2),"B",SWITCH(RANDBETWEEN(0,3),0,3,4),-1)

     

     

    Regards,

    Xiaoxin Sheng