Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Standard deviation

    Hi, I am working on my thesis and I want to calculate the idiosyncratic volatility which is de standard deviation of the abnormal return. My data looks as follows. I have panel data with 600 companies and their daily abnormal stock return over a ten year period. I want to compute the standard deviation per company per day and used the following code:
    Code:
    bysort id Date: egen IVOL = sd(Abnormalreturn) if !missing(Abnormalreturn)
    However, I only get missing values for the IVOL (see picture) How can I solve this?
    Click image for larger version

Name:	Scherm*afbeelding 2023-05-11 om 18.09.35.png
Views:	1
Size:	921.2 KB
ID:	1713295

  • #2
    It appears from your screenshot that the combination of id and date identifies unique observations. So you are asking Stata to calculate the standard deviation of Abnormalreturn in a set of just one observation. Sample standard deviations are not defined for singletons.

    To the limited extent I understand the concept of idiovol, it is a standard deviation of abnormal returns over some time interval, perhaps years, or months or decades, or whatever depending on your context. In any case, to get a standard deviation requires more than a single observation. So you will have to expand the time period, perhaps creating a new monthly or yearly time variable (or some other time span) and then replace Date with that other variable in your command.

    In the future, when asking for help with code, please use the -dataex- command and show example data. Although sometimes, as here, it is possible to give an answer that has a reasonable probability of being correct, this is usually not the case. Moreover, such answers are necessarily based on experience-based guesses or intuitions about the nature of your data. When those guesses are wrong, both you and the person trying to help you have wasted their time as you end up with useless code. To avoid this, a -dataex- based example provides all of the information needed to develop and test a solution.

    If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment

    Working...
    X