+ Reply to Thread
Results 1 to 3 of 3

Thread: Mean absolute error & count function

  1. #1
    Points: 37, Level: 1
    Level completed: 74%, Points required for next Level: 13

    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Mean absolute error & count function



    Dear Stata helpers,

    I'm a 3rd year Business Administration student working on a finance project about analyst forecast accuracy. My supervisor requires me to work with Stata which I never used before and haven't gotten any instructions whatsoever on how to work with this program. He has made it clear that I have to figure it out myself or with help from outside, so that's why I came to this forum for some help.

    I am using the IBES database from WRDS which lists the following data:
    Ticker (abbreviated firm name)
    Activation date (date of forecast)
    Year (derived from Activation date)
    Analyst code
    Estimated value (EPS forecast)
    Actual value (EPS)
    Absolute error (derived from Actual - Estimated)

    I've got two problems at hand:
    1. Mean absolute forecast error for a specific firm.
    I have the individual absolute forecast error of a specific analyst for a specific firm in a given year, but I also need a column right next to it that will show the mean absolute forecast error for the firm in a given year, this is to compute the measure for the dependent variable 'forecast accuracy'.
    >> What I tried is "mean abserror, over(ticker year)" but it returned me the 'no observations r(2000);' error?

    2.
    a. Counting number of years for which a analyst i made a forecast through year t.
    b. Counting number of years for which a analyst i made a forecast through year t for firm j.
    c. Counting number of firms for which a analyst i made a forecast through year t.

    What I tried is using the 'count observations using satisfying condition' in the menu which gave me the following commands:
    "by analys year, sort : count if abserror>=0" for a.
    "by analys year ticker, sort : count if abserror>=0" for b. and c.

    This helped me a lot because it actually showed me the results I needed.
    The only downside is I don't know how I make a variable out of it.
    >> For example I tried putting "gen countyears=" in front of the command but it didn't work.
    Also I need to find a way to separate b. and c. from each other as they both use the same kind of command. One counts number of years for a firm, the other counts number of firms for a year.

    Thank you in advance!

  2. #2
    RoboStataRaptor
    Points: 7,394, Level: 57
    Level completed: 22%, Points required for next Level: 156
    bukharin's Avatar
    Location
    Sydney, Australia
    Posts
    1,024
    Thanks
    9
    Thanked 243 Times in 236 Posts

    Re: Mean absolute error & count function

    I would probably use -egen- for these problems:

    1. egen meanabserror = mean(abserror), by(ticker year)
    2a. egen absgt0 = total(abserror>=0 & abserror<.), by(analys year)
    etc

    See -help egen- for more information

    You need the -abserror<.- because missing values in Stata are considered to be higher than any number. Therefore a missing value for abserror would be >=0 and would get counted, which is probably not what you want.

  3. #3
    Points: 37, Level: 1
    Level completed: 74%, Points required for next Level: 13

    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Re: Mean absolute error & count function


    Thank you very much for your input, this will definitely help me with the problem at hand!

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats