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
Within-between estimator with a lagged dependent variableHey, I have some CSTS data. I wish to use the "within-between" random effects estimator (Bell and J…
Creating a dynamic portfolio of returnsDear Statalist members, I am using Stata for the first time for my Masters Thesis and have tried to…
How to create drug classification variable using generic drug name variableHello. I am research student that is new to STATA and I am trying to learn how to create a drug clas…
stata evenstudy2 packageI use stata SE 14.2 version to do event study analysis. I'm using eventstudy2 package, but always so…
SADI: Sequence too longI am using SADI to do OMA. My data have 4 obervations with 3313 varialbes. When I do: oma V1-V3313, …
Subscribe to:
Post Comments (Atom)
0 Response to Sum of values of a conditional variable
Post a Comment