Announcement

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

  • Calculating stable ratios in given time period for given firms in panel data set

    Hi,
    I have a panel data set containing choosen financial data for thousands of companies. Some companies have data for 20 years, and some countries only have data for a few years. I have defined various ratios, such as Equity/Total assets, and want to calculate stable periods of given ratios for every firm. A condition is that the given ratio cannot change more than +/- 0.1 over a 10 year period. We want the first period to be from 2021 to 2012, next period 2020 to 2011 and so on.

    I've tried to calculate the moving average using: tsset id YEAR > tssmooth ma ma1=ER, window(10 0 0), without luck. I get a error message saying: window() invalid -- invalid numlist has elements outside allowed range.

    My questions are:

    1. How can I calculate the moving average for 10 years for all firms individually?

    2. How can only use the firms that have data for 10 years and changes in the range of +/- 0.1 over these 10 years. Meaning, I want to exclude all other firms in the calculations.

    Hope someone can help me out here

  • #2
    1. asrol will get you the rolling mean easily and quickly.

    2. you'd drop any firm with missing values on the variables of interest first, or asrol may provide missing values and you could drop on those.
    g dx = d.x . xtset your data and I don't think you'll need bysort. or bys id year: g dx = d.x.
    keep if abs(dx)<=0.1

    Last edited by George Ford; 16 Feb 2023, 09:02.

    Comment

    Working...
    X