Hi,
I am having some troubles in computing functions over subgroups.
Basically, I have some financial data over a time period of 4 years for some firms and I would like to create a variable for the mean or the sum of these data by year. You can see in the attachment how my data looks like.
I tried this code:
bysort Date: egen meanPrice= mean(Price),
but it generates the mean for each signle observations, instead of having the mean for each of the years.
I know that with the commad collapse it works, but then I would need to add the new variable with the old dataset and I cannot it merge it.
Could you please help me?
Thank you in advance!
Related Posts with Problem with calculating functions over subgroups
New version of xcontract )AGAIN) on SSCThanks once again to Kit Baum, a new version of the xcontract package (superseding yesterday's versi…
Overlapping values on y axis in Stata graphArray Hi, is there a way to avoid overlapping of numbers on the y axis …
Median, Tercile and QuartileHi, I want to create dummy variables based on the median. Sometiems I do that based on quartile and …
spmap optionsHello, I used -spmap- to map US employment and this is the code I used: Code: spmap cbp_emp_sum u…
Outreg2 to Excel R(198) error diagnosisI am trying to run the below code in STATA 16.1. STATA is fully updated, and I've uninstalled and re…
Subscribe to:
Post Comments (Atom)
0 Response to Problem with calculating functions over subgroups
Post a Comment