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
Not concave message on my IRT modelsHello, I am new to IRT models. I am trying to run an irt 1pl or 2pl for a test administered to stude…
Create variable - mean per ageHello, I would like to create a variable that says the mean value of income (prfitba_w3) by age (dv…
The Null hypothesis of t-test in non-linear least-squares ?I'm reading a paper named "Flows of knowledge from universities and federal laboratories:Modeling th…
Same observations across all models without using e(sample)Hello! I'm running a set of regressions using Employer-Employee Data (LEED). I'm a running a OLS, wo…
Changing axes font in graphHi. I'm struggling to change the font of the x and y axes of a line graph. The following code change…
Subscribe to:
Post Comments (Atom)
0 Response to Sum of values of a conditional variable
Post a Comment