Hello everyone,
I'm working with a dataset that includes variables named aar_before, bar_before, aar_after, and bar_after. My task involves generating four new variables: avg_aar_before, avg_bar_before, avg_aar_after, and avg_bar_after. The objective is to calculate the average values when the "during alert" condition is equal to 1, both for the before and after periods separately. The computed mean values should then be assigned to their respective generated variables. It's important to note that this process needs to be repeated for each instance where during alert equals 1 in the dataset.
Thank you.
I'm working with a dataset that includes variables named aar_before, bar_before, aar_after, and bar_after. My task involves generating four new variables: avg_aar_before, avg_bar_before, avg_aar_after, and avg_bar_after. The objective is to calculate the average values when the "during alert" condition is equal to 1, both for the before and after periods separately. The computed mean values should then be assigned to their respective generated variables. It's important to note that this process needs to be repeated for each instance where during alert equals 1 in the dataset.
Thank you.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(during_alert before_alert after_alert) float(aar_before bar_before aar_after bar_after) . 0 . .20162995 .04260506 . . . 0 . .16719356 .05624989 . . . 0 . .1674138 .08249592 . . . 0 . .19701643 .07580585 . . . 0 . .20516405 .06666745 . . . 0 . .14018941 .06387276 . . . 0 . .09170595 .15080187 . . . 0 . .11421962 .6173893 . . . 0 . .1097358 .5896134 . . . 0 . .08595602 .5171338 . . . 0 . .09839484 .1326193 . . . 0 . .11376492 .009647326 . . . 0 . .09372236 .018008037 . . 1 . . . . . . 1 . . . . . . 1 . . . . . . 1 . . . . . . 1 . . . . . . 1 . . . . . . 1 . . . . . . 1 . . . . . . . . . . . . . . . . . . . . 1 . . . . . . 1 . . . . . . . . 2 . . .11574279 .05181787 . . 2 . . .12310397 .1470303 . . 2 . . .15871197 .09303033 . . 2 . . .17397007 .09428933 . . 2 . . .19201784 .13814032 . . 2 . . .21083596 .06707024 . . 2 . . .06125252 .05421273 . . 2 . . .10629333 .06610985 . . 2 . . .1511041 .06177737 . . 2 . . .1929069 .0454968 . . 2 . . .2569058 .03125316 . . 2 . . .1495269 .065860316 . . 2 . . .14967504 .06347345 . . 2 . . .15980107 .06372144 . . 2 . . .17556715 .06438817 . . 2 . . .16668437 .06492964 . . 2 . . .15992224 .07937814 . . 2 . . .1705421 .10644616 . . 2 . . .15192135 .05132644 . . 2 . . .20728523 .04138765 . . 2 . . .2180869 .05178387 . . 2 . . .13485567 .06152795 . . 2 . . .16922466 .07246478 . . 2 . . .1477594 .06227433 . . 2 . . .1310007 .02980627 . . 2 . . .14637494 .04522794 . . 2 . . .17402603 .05784023 . . 2 . . .1879326 .05905496 . . 2 . . .19642372 .05652686 . . 2 . . .18656853 .05157323 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 0 . .18682347 .04846417 . . . 0 . .18203865 .05410815 . . . 0 . .19029137 .04600076 . . . 0 . .18831116 .05591399 . . . 0 . .1826687 .04333993 . . . 0 . .1983744 .04931277 . . . 0 . .2106632 .0404925 . . . 0 . .2075484 .04315845 . . . 0 . .2073653 .04033995 . . . 0 . .2142975 .05041032 . . . 0 . .2089373 .04338308 . . . 0 . .21928607 .05291648 . . . 0 . .2107713 .0503378 . . . 0 . .1781201 .05150358 . . . 0 . .13056736 .05822437 . . . 0 . .07920727 .25142273 . . . 0 . .15313464 .6125321 . . . 0 . .3512289 .45004416 . . . 0 . .3157814 .0511076 . . . 0 . .25571802 .5715104 . . . 0 . .20302093 .04302251 . . . 0 . .16239607 .04033545 . . . 0 . .06975425 .03884154 . . . 0 . .13212495 .03941067 . . . 0 . .1186699 .03726508 . . . 0 . .10896995 .03512837 . . . 0 . .07709385 .08729947 . . . 0 . .1267967 .021012183 . . . 0 . .10955705 .020384533 . . . 0 . .1121116 .04369621 . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . 2 . . .16088095 .07666578 . . 2 . . .1606727 .08362246 . . 2 . . .1573334 .07126608 . . 2 . . .17286213 .04736475 . . 2 . . .20819326 .04837189 . . 2 . . .11442523 .05570864 . . 2 . . .13974726 .05125762 . . 2 . . .18766673 .05887006 . . 2 . . .3325168 .03942842 . . 2 . . . . . . 2 . . .2620991 .09743398 . . 2 . . .3336086 .09014753 . . 2 . . .3330782 .03789013 . . 2 . . .3600489 .033888653 . . 2 . . .13572246 .07926671 . . 2 . . .2793817 .06111742 . . 2 . . .27600557 .05564579 . . 2 . . .1557568 .04432066 . . 2 . . .18025704 .06572154 . . 2 . . .1859729 .05975353 . . 2 . . .18460834 .02919079 . . 2 . . .30906445 .04670005 . . 2 . . .2640435 .08850385 . . 2 . . .18724415 .05567451 . . 2 . . .141274 .0551312 . . 2 . . .1772512 .0409829 . . 2 . . .20125324 .10353238 . . 2 . . .26772735 .5892562 . . 2 . . .337844 .26351514 . . 2 . . .151304 1.0520319 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . end
Comment