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.
Related Posts with Sum of values of a conditional variable
Using cii proportions with loopHello, I am trying to compute confidence intervals for proportions (number of cases / total) on eac…
Pseudo Panel Data and Mediation AnalysisDear Stata Experts I'm a PhD student, and I'd like to know how to use the codes to perform the Medi…
Please help cant work out how to t-test. Im new to stataHi guys I'm struggling to compare 2 different regions with a t-test. As seen from the screenshots I…
Adding rows under a variableStata command for adding rows lets say 10 rows under a variable which has fixed observations like 40…
please help. making bar graph more simple with "over" optionsHi, guys. I'm a newcomers with stata, and there is some trouble in making bar graph. My data has 4…
Subscribe to:
Post Comments (Atom)
0 Response to Sum of values of a conditional variable
Post a Comment