Hello,
my dataset is structered the following:
clear
input float (group_id won_close_dummy loss_close_dummy)
1 0 1
2 1 0
2 1 0
3 1 0
6 1 0
7 0 1
9 0 0
13 0 1
13 1 0
13 0 1
13 0 1
17 1 0
17 0 1
18 0 1
20 1 0
21 1 0
24 1 0
24 1 0
25 0 1
28 0 1
33 1 0
34 1 0
35 1 0
38 0 0
42 1 0
43 1 0
43 1 0
43 1 0
43 1 0
43 1 0
45 1 0
45 0 1
46 0 1
46 1 0
47 1 0
47 0 1
I now want to create a new binary variable "donated" which takes the value of 0 if within a group there is at least one 1 for both "won_close_dummy" and "loss_close_dummy". This means if within a group (eg. group_id ==13 or group_id==17) both variables "won_close_dummy" and "loss_close_dummy" have at least one 1 the new variable "donated" should get a 0 for the whole group.
If within a group (eg. group_id==2 or group_id==43) only one variable has a 1 the new variable "donated" should get a 1 for the hole group.
This means it should look like this in the end:
input float(group_id won_close_dummy loss_close_dummy donated)
1 0 1 1
2 1 0 1
2 1 0 1
3 1 0 1
6 1 0 1
7 0 1 1
9 0 0 1
13 0 1 0
13 1 0 0
13 0 1 0
13 0 1 0
17 1 0 0
17 0 1 0
18 0 1 1
20 1 0 1
21 1 0 1
24 1 0 1
24 1 0 1
25 0 1 1
28 0 1 1
33 1 0 1
34 1 0 1
35 1 0 1
38 0 0 1
42 1 0 1
43 1 0 1
43 1 0 1
43 1 0 1
43 1 0 1
43 1 0 1
45 1 0 0
45 0 1 0
46 0 1 0
46 1 0 0
47 1 0 0
47 0 1 0
I hope you can help me solving this problem. Thanks in advance!
Greetings
Marcel
Related Posts with Create a new variable based on observations within a group
boottest now does "bootstrap-c" advocated by Alwyn YoungAt the suggestion of James MacKinnon, I've added an option to boottest that lets you bootstrap the d…
boottest now offers "bootstrap-c" advocated by Alwyn YoungAt the suggestion of James MacKinnon, I've added an option to boottest that lets you bootstrap the d…
generating new variable from panel data.*I have multiple observations for individuals. My data is long. I have a columns for whether the even…
How to create dummy variables for day of the week, day of the month etc.Hello, I am fairly new at using stata, thus since I want to control for time varying influences (my …
Show number of respondentsHi Statalist! A quick and (likely) easy question here: I have been searching for ways to find the nu…
Subscribe to:
Post Comments (Atom)
0 Response to Create a new variable based on observations within a group
Post a Comment