Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# RE: st: RE: Use 2 variables to gen 10 new variables

 From Jonathan Grondin To statalist2 Subject RE: st: RE: Use 2 variables to gen 10 new variables Date Thu, 28 Jul 2011 13:57:18 +0000

```Indeed, I'll try to present it less ad hoc.

Let's see it that way:

I have 2 variables X1 and X2, each holding 5 values (Y1 to Y5). Instead, I'd like to create 5 variables: Y1 through Y5 holding 2 values (X1 & X2)

Y1     Y2    Y3    Y4    Y5

X1:    2     6     3     7      1

X2:    4     2     4     8      2

I've taken a look at -contract- but can't manage a simple way of doing it.
Any suggestions ?

Jonathan

> From: n.j.cox@durham.ac.uk
> To: statalist@hsphsun2.harvard.edu
> Date: Wed, 27 Jul 2011 19:15:19 +0100
> Subject: st: RE: Use 2 variables to gen 10  new variables
>
> This sounds very ad hoc. Consider instead the possibilities for producing new reduced datasets by -contract- and -collapse-.
>
> Nick
> n.j.cox@durham.ac.uk
>
> Jonathan Grondin
>
> I have a questionnaire answered by two groups (group "a" and group "b").
> Every question had to be answered by a value of 1 through 10. Every question is then divided into 2 variables, e.g Question 1: "q1a" and "q1b".
>
> I would like to combine q1a and q1b together and create 10 variables out of them each of them holding the frequency of the two groups. e.g. "q1a" and "q1b" would generate: "new_q1_1" to "new_q1_10".
> Every new variable would hold two values: new_q1_1 would hold the frequency of people in group "a" who answered "1" and the frequency of people in group "b" who answered "1".
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```