Restructure data

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Restructure data

mils
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
mils
Reply | Threaded
Open this post in threaded view
|

Restructure file

mils
Hi everyone,

I have the following data:

id  timeperiode  brand
1   q1                a
1   q1                a
2   q1                a
2   q1                b
2   q1                b
3   q1                c
.
.
.
43  q2                b
.
.
.

and I woul like to restructure the data to look like:

timeperiode  brand   counts    percentage
 q1                a           3          50
 q1                b           2          33
 q1                c           1          17

any help will be much appreciate.

Please, let me know if you need more information.

Thanks in advance.





-----
mils
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Restructure-file-tp5724361.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
mils
Reply | Threaded
Open this post in threaded view
|

Re: Restructure data

Andy W
In reply to this post by mils
************************************************************.
*Orig data.
data list free / timeperiode brand (2A2) counts weighting.
begin data.
q1           a    1         0.6
q1           a    1         0.6
q1           a    1         0.6
q1           b    2         0.4
q1           b    2         0.4
q1           c    3         0.2
end data.

*1st Aggregate - note I use timeperiode as a break variable as well (a guess).
dataset declare agg.
aggregate outfile = 'agg'
  /break = timeperiode brand
  /counts=N  /*could use FIRST(counts) here as well given your example */
  /weighting=SUM(weighting).
dataset activate agg.

*2 find totals to calc prop.
aggregate outfile = * mode=addvariables
  /break = timeperiode
  /countsTot=SUM(counts)
  /weightingTot=SUM(weighting).
 
compute proportions = (counts/countsTot)*100.
compute weighting_proportions = (weighting/weightingTot)*100.
*match files file = * /drop counts weighting countsTot weightingTot.
freq var proportions weighting_proportions /format = notable /statistics = sum.
************************************************************.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Restructure data

David Marso
Administrator
In reply to this post by mils
Please look up the AGGREGATE command!
--
mils wrote
Hi everyone,

I have the following data:

timeperiode brand counts weighting
q1           a    1         0.6
q1           a    1         0.6
q1           a    1         0.6
q1           b    2         0.4
q1           b    2         0.4
q1           c    3         0.2

and I would like to restructure the data to make the data look like this:
                       
timeperiode brand counts weighting
q1           a    3            1.8
q1           b    2            0.8
q1           c    1            0.2

and finally to look like this:
                       
timeperiode brand proportions weighting_proportions
q1           a     50      64
q1           b     33      29
q1           c     17       7

Any help would be much appreciate it.

Thanks in advance.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Restructure data

David Marso
Administrator
In reply to this post by mils
Mils,
In the future please don't double post under two separate topics!
D.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"