How to generate dummy variables based on multiple if criteria
Mostra commenti meno recenti
I need to generate a few dummy variables and would like your input on this.
In the dataset, there are 10 observations per participant and each participant is allocated to one of the four treatments (1,2,3,4). The choice is to select either "1" or "2" in 10 tasks (taskno). Below are the first few observations.

Now, I would like to generate a dummy variable, let's call it dummy_1, such that once the participant selects the choice 2 and the treatno is 1, then the dummy_1 should be equal to 1 for all the remaining observations (taskno) for the same participant.
For instance, in the above example, participant 1 selected choice 2 in the second task. Now for rest of the observations (taskno: 3 to 10) for participant 1, the dummy_1 should be equal to 1 (irrespective of participant 1 choices in taskno 3 to 10). The same would apply to participant 2 and so on.
The output should be:

Any help in this regard would be appreciated. Thanks.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Multidimensional Arrays in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!