Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte likes int(date date1) str4 colour byte SUMIFSred 1 18105 18001 "Red" 0 0 18159 18002 "Blue" 0 1 18161 18003 "Red" 0 1 18161 18004 "Blue" 0 2 18222 18005 "Blue" 0 1 18225 18006 "Red" 0 2 18226 18160 "Red" 0 1 18252 18161 "Blue" 1 3 18253 18009 "Red" 0 1 18261 18010 "Blue" 0 1 18261 18011 "Red" 0 1 18276 18012 "Blue" 0 1 18276 18013 "Red" 0 0 18276 18105 "Red" 1 end format %tddd-Mon-YY date format %tddd-Mon-YY date1
I have tried with the following code but it does not quite work out:
save tmpfile1, replace
collapse (sum) total_likes_ifs_red = likes if colour == "Red", by(date)
ren date date1
merge 1:m date1 using tmpfile1
drop if _merge==1
drop _merge
Please help. Thank you.
0 Response to Two conditions for summing a variable
Post a Comment