I am new to using Stata, I have always made corrections using already clean bases.
I have the variables "sales" and "economic_sector". I need to create another variable called "MARKET_SHARE", which calculates the ratio of sales to total sales by economic sector.
I was trying to calculate the value of total sales given the condition like this:
egen float TOTAL_1=rowtotal(cond(economic_sector==1,sales,0))
egen float TOTAL_2=rowtotal(cond(economic_sector==2,sales,0))
egen float TOTAL_3=rowtotal(cond(economic_sector==1,sales,0))
gen marketshare = 0
replace marketshare=sales/TOTAL_1 if economic_sector==1
replace marketshare=sales/TOTAL_2 if economic_sector==2
replace marketshare=sales/TOTAL_3 if economic_sector==3
but replace marketshare=sales/TOTAL_1 if economic_sector==1, gives me "factor variables and time-series operators not allowed"
Any help would be very usefull.
0 Response to Sum of values of a conditional variable
Post a Comment