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
Export variance covariance matrix to csv fileFor example, sysuse auto, clear I want to export the variance - covariance of variable price mpg h…
reg2hdfespatialDear all, I want to use this link to install the user-written command -reg2hdfespatial-in Stata. ht…
calculate score in StataHello, I gave variables like this: Array Which means: 0. Not using 1. Pill 2. IUD 3. Inje…
Oaxaca with instrumental variableDear all, I am trying to use an Oaxaca- Blinder decomposition to see if a variable of interest cont…
Generating Quarters from date variableHi All, I want to generate quarters in my data set. I have my date variable in the D-M-Y format. I …
Subscribe to:
Post Comments (Atom)
0 Response to Problem with calculating functions over subgroups
Post a Comment