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: Reshaping long to wide data from complex experimental design


From   Russell Dimond <[email protected]>
To   [email protected]
Subject   Re: st: Reshaping long to wide data from complex experimental design
Date   Fri, 30 Nov 2012 12:05:22 -0600

Hi Bastien,

You have three levels of hierarchy here:

Level 3 is Groupe, which is not relevant for the moment.
Level 2 is Participant.
Level 1 is "recording."

The -reshape- command's j() option needs a single variable that identifies each recording. You don't have one at this point--you have a compound identifier consisting of (if I've got this right) Phase, Distance and Répétition. -reshape- can't work with that directly. I'd suggest something like this:

sort Participant Phase Distance Répétition
by Participant: gen recording =_n
reshape wide Phase Distance Répétition Erreur_Absolue, i(Participant) j(recording)

This will leave you with variables Erreur_Absolue1 through Erreur_Absolue80, with corresponding variables Phase1-Phase80, Distance1-Distance80, and Répétition1-Répétition80 telling you the other characteristics of each "recording." I wonder if you could work with the data in that form. If not, you can rename the variables to what you had in mind with something like the following:

local rec 1
forval p=1/2 {
    forval d=1/5 {
        forval r=1/8 {
            rename Erreur_Absolue`rec' Phase`p'Distance`d'Répétition`r'
            local rec `++rec'
        }
    }
}

Russell Dimond
Statistical Computing Specialist
Social Science Computing Cooperative
University of Wisconsin-Madison


On 11/30/2012 10:25 AM, Bastien Christian wrote:
I Nick,

Thanks for your advice.
I did look at the available help, but did non find an answer.

Here is an example of the data :
Groupe = Group (Réel, Augmenté) (between subject factor) (10 subjects per group)
Participant = participant id
Genre = Gender
Age
Phase (1 2) (within factor)
Distance = (8 15 23 28 33) (within factor)
Répétition : Repetition (1 2 3 4 5 6 7 8) (within factor)
Erreur_Absolue = Abs(distance error) the dependent variable

With this design, I get 800 recordings.
For each subject, we have 80 recordings.

Long Format:

Groupe	Participant	Genre	Age	Phase	Distance	Répétition	Erreur_Absolue
Réel	1	Femme	27	1	8	1	0.1
Réel	1	Femme	27	1	8	2	0.0
Réel	1	Femme	27	1	8	3	0.1
Réel	1	Femme	27	1	8	4	0.0
Réel	1	Femme	27	1	8	5	0.0
Réel	1	Femme	27	1	8	6	0.1
Réel	1	Femme	27	1	8	7	0.0
Réel	1	Femme	27	1	8	8	0.0
Réel	1	Femme	27	1	15	1	1.8
Réel	1	Femme	27	1	15	2	0.2
Réel	1	Femme	27	1	15	3	0.0
Réel	1	Femme	27	1	15	4	0.4
Réel	1	Femme	27	1	15	5	0.4
Réel	1	Femme	27	1	15	6	0.0
Réel	1	Femme	27	1	15	7	0.2
Réel	1	Femme	27	1	15	8	0.1
Réel	1	Femme	27	1	23	1	0.4
Réel	1	Femme	27	1	23	2	1.0
Réel	1	Femme	27	1	23	3	1.2
Réel	1	Femme	27	1	23	4	0.2
Réel	1	Femme	27	1	23	5	0.6
Réel	1	Femme	27	1	23	6	0.4

What I would like to have : 1 line per participant

Groupe, Participant, Genre, Age, Phase1Distance1Répétition1, …, Phase1Distance1Répétition8, Phase1Distance2Répétition1,…,Phase1Distance2Répétition8, …, Phase2Distance5Répétinion8

For the variables such as Phase1Distance1Répétition1 I would have

As for the code, I just can't figure out the syntax. I tried to reshape with the dialogue box, but I always get an error message indicating that the Participant for example, is not unique within Groupe; there are multiple observations at the same Participant within Groupe.

Hope this will help,
Christian Bastien

Le 30 nov. 2012 à 16:32, Nick Cox <[email protected]> a écrit :

It is better to give a concrete example of what your data look like
and to show code you tried on which we can comment.

See http://www.stata.com/statalist/archive/2012-11/msg01106.html

for a recent example in which a similar question got nowhere because
too few concrete details were given.

See also the help for -reshape-, the manual entry and

FAQ     . . . . . . . . . . . . . . . . . . . . . . . .  Problems with reshape
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        8/05    I am having problems with the reshape command. Can
                you give further guidance?
                http://www.stata.com/support/faqs/data-management/
                problems-with-reshape/



Nick

On Fri, Nov 30, 2012 at 3:08 PM, Bastien Christian
<[email protected]> wrote:

In order to analyse data with MANOVA for repeated measures, I would like to reshape my data from a long to a wide format.

My design use 1 between factor (Group{2}) and 3 repeated factors (Trials(8), Distance(5), Phase(2)).
In fact the between factors allows the counterbalancing of the Phase Conditions.

Thus, each participant goes through 2 phases.
In each phase 5 target positions are used, and for each position there is 8 trials.
The task consists in positioning a virtual object as near as possible to the target. We measure the distance between the virtual object and the target.

I tried to use the "reshape" command but failed.
I just can't handle the syntax for 3 repeated measure.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


Attachment: smime.p7s
Description: S/MIME Cryptographic Signature



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