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
test for statistical differenceHi Stata fam I would like to test for statistical difference between responses from two different po…
Two-way table where cells are %s and Totals are frequenciesHello, Is there a way to create a two-way table where the cells are percentages and the totals are …
Competing risks in survival analysesDear reader, I would like to know the difference in my survival analysis approach. I have 4 types o…
reghdfe - "noconstant" as standard optionDear community, I would please like to ask for your help concerning the following question. Recent…
Transforming time series data into Panel data Hello, I have a time series dataset, downloaded from UNCTAD. Then I pasted the data into Stata data…
Subscribe to:
Post Comments (Atom)
0 Response to Sum of values of a conditional variable
Post a Comment