Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int(id dum1 dum2 dum3 dum4) float (price newprice ) 1 1 0 0 0 20 20 1 0 1 0 0 30 32.5 1 0 0 1 0 25 25 1 0 0 0 1 20 22.5 1 0 0 0 1 25 22.5 1 0 1 0 0 35 32.5 1 0 1 0 0 32.5 32.5 end
Hi, in the above data, I want to create newprice as the mean of price for each category of dummies taking value 1.
for example, newprice takes value 22.5 ( average of 20 and 25) where dum4 takes value 1.
Similarly, newprice takesvalue 32.5 ( average of 30, 35 and 32.5) where dum2 takes value 1.
How should I go about creating newprice ?
Thanks.
0 Response to Creating a new variable
Post a Comment