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
Calculating a tenure proxyHello everyone, I want to calculate auditor tenure variable from the following variables: firm id, y…
Parmby gives 'normal' instead of 'logit' confidence intervals when using proportion commandAfternoon all, I have a question about the excellent parmby module, provided by Roger Newson. As a…
ddeviance result differs from MinitabFor the delta deviance influence diagnostic in logistic regression ddeviance from predict (using v 1…
How to deal with a big dataset?I am trying to run OLS regression with my panel dataset of over 100,000,000 observations. My target …
Help Needed With Interpreting Multiple Categorical by Categorical InteractionsDear All: I suddenly found myself confused in interpreting multiple interactions of categorical var…
Subscribe to:
Post Comments (Atom)
0 Response to Sum of values of a conditional variable
Post a Comment