Bookmark and Share

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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From   Jonathan Grondin <[email protected]>
To   statalist2 <[email protected]>
Subject   RE: st: RE: Use 2 variables to gen 10 new variables
Date   Thu, 28 Jul 2011 14:59:36 +0000

Here is a tabulate of the two variables X1 and X2 holding each 5 values


 tab X1
       X1 |      Freq.     Percent        Cum.
------------+-----------------------------------
          Y1 |        2       10.53       10.53
          Y2 |        6       31.58       42.11
          Y3 |        3       15.79       57.89
          Y4 |        7       36.84       94.74
          Y5 |        1        0.05       100
          
------------+-----------------------------------
      Total |        19      100.00


 tab X2

       X2 |      Freq.     Percent        Cum.
------------+-----------------------------------
          Y1 |        4       20.00       20.00
          Y2 |        2       10.00       30.00
          Y3 |        4       20.00       50.00
          Y4 |        8       40.00       90.00
          Y5 |        2       10.00       100
         
------------+-----------------------------------
      Total |        20      100.00




I would like to create 5 variable (Y1 to Y5) holding two values each (from prior X1 and X2)
e.g.:


tab Y1



       Y1 |      Freq.     Percent        Cum.

------------+-----------------------------------

          X1|        2       33.33       33.33

          X2|        4       66.67      100.00

                  

------------+-----------------------------------

      Total |        6      100.00


tab Y2





       Y2 |      Freq.     Percent        Cum.


------------+-----------------------------------


          X1|        6       75.00       75.00


          X2|        2       25.00      100.00


                  


------------+-----------------------------------


      Total |        8      100.00

etc.


Any suggestions ?


Jonathan


----------------------------------------
> Date: Thu, 28 Jul 2011 15:13:02 +0100
> Subject: Re: st: RE: Use 2 variables to gen 10 new variables
> From: [email protected]
> To: [email protected]
>
> Sorry, but I can't relate your example to a Stata dataset. Rows and
> columns can't both be Stata variables. Please show your example as
> produced by a Stata command and show how you are holding the data
> within Stata.
>
> On Thu, Jul 28, 2011 at 2:57 PM, Jonathan Grondin
> <[email protected]> wrote:
> > 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: [email protected]
> >> To: [email protected]
> >> 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
> >> [email protected]
> >>
> >> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index