Skip to content
Stata.Professor : Your Partner in Research Logo

  • Home
  • Paid Help
    • Empirical Models using Stata®
    • Data Management
    • Paid Help | Pricing
    • Paid Help – Frequently Asked Questions (FAQs)
    • Privacy
  • Completed Projects
    • Asset Pricing Models
      • Fama and French Model
      • Fama – MacBeth
      • Bootstrap Fund Performance
      • Investors attention
      • Misvaluing Innovation
    • Implied cost of equity (ICC)
      • Gebhardt et al. (2001) – GLS
      • ICC GLS Model
      • Claus and Thomas (2001)
      • Cost of Equity using CAPM & FF3
      • Mutual Funds performance
    • Event studies
      • Event study methodology
      • Returns to New IPOs
      • Share repurchases
    • Momentum & Trading
      • asm Momentum Portfolios
      • Absolute Strength Momentum
      • Non-parametric momentum
      • Trading rules
      • Herding behavior
      • Sentiment, disagreement
    • KMV – Default Probability
    • Earning Management Model
    • Market Liquidity
      • Market liquidity models
      • Bid Ask Spread
    • Volatility
      • Backtesting VaR Models
      • P42 – Volatility portfolios
      • P31 – Realized volatility
      • Volatility Managed Portfolios
      • Expected Idiosyncratic Skewness
    • CEO debt and R&D
    • Zero-leverage firms
    • Financial Statement Comparability
  • Stata Programs
    • ASDOC: Stata to Word
      • asdoc : examples
      • asdoc : Tables of summary statistics
    • ASROL: Rolling window stats
    • ASREG: rolling regressions
    • ASTILE: for Portfolios and Groups
    • ASCOL: Converts Data Frequency
    • ASM: Momentum Portfolios
    • Stata Random Tips
    • Download Statistics
  • BLOG
  • ForumsbbPress Forums
  • About Us
  • Home
  • Paid Help
    • Empirical Models using Stata®
    • Data Management
    • Paid Help | Pricing
    • Paid Help – Frequently Asked Questions (FAQs)
    • Privacy
  • Completed Projects
    • Asset Pricing Models
      • Fama and French Model
      • Fama – MacBeth
      • Bootstrap Fund Performance
      • Investors attention
      • Misvaluing Innovation
    • Implied cost of equity (ICC)
      • Gebhardt et al. (2001) – GLS
      • ICC GLS Model
      • Claus and Thomas (2001)
      • Cost of Equity using CAPM & FF3
      • Mutual Funds performance
    • Event studies
      • Event study methodology
      • Returns to New IPOs
      • Share repurchases
    • Momentum & Trading
      • asm Momentum Portfolios
      • Absolute Strength Momentum
      • Non-parametric momentum
      • Trading rules
      • Herding behavior
      • Sentiment, disagreement
    • KMV – Default Probability
    • Earning Management Model
    • Market Liquidity
      • Market liquidity models
      • Bid Ask Spread
    • Volatility
      • Backtesting VaR Models
      • P42 – Volatility portfolios
      • P31 – Realized volatility
      • Volatility Managed Portfolios
      • Expected Idiosyncratic Skewness
    • CEO debt and R&D
    • Zero-leverage firms
    • Financial Statement Comparability
  • Stata Programs
    • ASDOC: Stata to Word
      • asdoc : examples
      • asdoc : Tables of summary statistics
    • ASROL: Rolling window stats
    • ASREG: rolling regressions
    • ASTILE: for Portfolios and Groups
    • ASCOL: Converts Data Frequency
    • ASM: Momentum Portfolios
    • Stata Random Tips
    • Download Statistics
  • BLOG
  • ForumsbbPress Forums
  • About Us
  • Home
  • Paid Help
    • Empirical Models using Stata®
    • Data Management
    • Paid Help | Pricing
    • Paid Help – Frequently Asked Questions (FAQs)
    • Privacy
  • Completed Projects
    • Asset Pricing Models
      • Fama and French Model
      • Fama – MacBeth
      • Bootstrap Fund Performance
      • Investors attention
      • Misvaluing Innovation
    • Implied cost of equity (ICC)
      • Gebhardt et al. (2001) – GLS
      • ICC GLS Model
      • Claus and Thomas (2001)
      • Cost of Equity using CAPM & FF3
      • Mutual Funds performance
    • Event studies
      • Event study methodology
      • Returns to New IPOs
      • Share repurchases
    • Momentum & Trading
      • asm Momentum Portfolios
      • Absolute Strength Momentum
      • Non-parametric momentum
      • Trading rules
      • Herding behavior
      • Sentiment, disagreement
    • KMV – Default Probability
    • Earning Management Model
    • Market Liquidity
      • Market liquidity models
      • Bid Ask Spread
    • Volatility
      • Backtesting VaR Models
      • P42 – Volatility portfolios
      • P31 – Realized volatility
      • Volatility Managed Portfolios
      • Expected Idiosyncratic Skewness
    • CEO debt and R&D
    • Zero-leverage firms
    • Financial Statement Comparability
  • Stata Programs
    • ASDOC: Stata to Word
      • asdoc : examples
      • asdoc : Tables of summary statistics
    • ASROL: Rolling window stats
    • ASREG: rolling regressions
    • ASTILE: for Portfolios and Groups
    • ASCOL: Converts Data Frequency
    • ASM: Momentum Portfolios
    • Stata Random Tips
    • Download Statistics
  • BLOG
  • ForumsbbPress Forums
  • About Us

asrol : Stata | Find statistics excluding focal observation

  • View Larger Image

asrol : Stata | Find statistics excluding focal observation

Introduction

In this blog post, we will explore the capabilities of asrol for calculating descriptive statistics in a rolling window or over a grouping variable while excluding focal observations.  asrol is a Stata command that facilitates the calculation of descriptive statistics. It can handle various data structures, including time series and panel data, and efficiently manage missing values, duplicate values, and time series gaps. Some of the statistics that can be estimated using asrol include mean, standard deviation, minimum, maximum, percentiles, median, missing values, count, first and last observations, product, and geometric mean. Moreover, asrol provides options to exclude focal observations or observations defined by a grouping variable, enabling even more flexibility in the analysis.

1. Excluding Focal Observations

The option xf in asrol allows us to exclude focal observations while calculating the required statistics. There are two flavors of excluding focal observations: excluding only the current observation or excluding all observations of the relevant variable with similar (duplicate) values in the given window.

Example A: Excluding Current Observation

Let’s consider the following dataset with 5 observations, where X is the variable of interest, and year is the range variable.

. asrol X, stat(mean) xf(focal) gen(xfocal)

+---------------------------------------+
| year     X        xfocal       xfyear |
|---------------------------------------|
| 2001   100          350           350 |
| 2002   200          325           325 |
| 2003   300          300     266.66667 |
| 2003   400          275     266.66667 |
| 2004   500          250           250 |
+---------------------------------------+

In Example A, we use xf(focal) to exclude the current observation. The generated variable xfocal contains the mean values of the remaining observations in the given window, excluding the focal observation. For instance, in the year 2001 , xfocal has a value of 350, which is the average of the values of X in the years 2002, 2003, 2003, and 2004: (200+300+400+500)/4 = 350. Similarly, the second observation of xfocal is 325, calculated as (100+300+400+500)/4 = 325.

2. Exclude by groups

asrol also allows excluding focal observations based on a grouping variable. If we use xf(year) to define the focal observation(s), all observations belonging the variable year will be excluded that are similar to the current observation.  See the following example and its explanation.

. asrol X, stat(mean) xf(year) gen(xfyear)

       obs 1: (200 + 300 + 400 + 500)/4 = 350          
       obs 2: (100 + 300 + 400 + 500)/4 = 325          
       obs 3: (100 + 200 + 500 )     /3 = 266.66667    
       obs 4: (100 + 200 + 500 )     /3 = 266.66667    
       obs 5: (100 + 200 + 300 + 400)/4 = 250          

Example B differs from Example A in definition of the focal observation(s). In Example B, we invoke the option xf() as xf(year), where year is an existing numeric variable. With this option, the focal observation(s) is(are) defined as the current observation and other observations where the focal observation of the rangevar has duplicates. Our data set has two duplicate values in the rangevar , i.e., year 2003. Therefore, the mean values are calculated as shown above.

Examples

Example 1: Exclude focal in rolling window

webuse grunfeld
 
bys company: asrol invest, stat(mean) xf(focal)

Example 2: Exclude focal in no-rolling window

* Find Standard Deviation: last 5 years 
* excluding the current observation or the most recent one 

webuse grunfeld
 
bys company: asrol invest, stat(sd) win(year -5 -1)

Example 4: Exclude by groups in no-rolling window

webuse grunfeld
 
bys company: asrol invest, stat(mean) xf(company)

Explanation: The above command finds standard deviation for whole sample while excluding the focal company. Therefore, when the company is equal to 1, the standard deviation is based on the remaining 19 companies. Similarly, when the company is 2, the standard deviation is based on the first company, and companies 3 to 20.

See Alos

asm : for momentum portfolios
asdocx : Easily create publication-quality tables from Stata and export to Word, Excel, LaTeX
asdoc : Easily create publication-quality tables from Stata
astile : for creating fastest quantile groups
asgen : for weighted average mean
asrol : for rolling-window statistics
asreg : for rolling-window, by-group, and Fama and MacBeth regressions
ascol : for converting asset returns and prices from daily to a weekly, monthly, quarterly, and yearly frequency
searchfor : for searching text in data sets
flexmat : Creates a flexible matrix of real, string and complex elements

Attaullah Shah2023-07-13T17:59:12+05:00July 13th, 2023|asrol|0 Comments

Leave A Comment Cancel reply

Paid Help Menu

  • What is Paid Help
  • Paid Help | Pricing
  • Paid Help – FAQs
  • List of Completed Projects
  • Details of All Projects
  • Our Stata Programs
  • Contact

Key Links

  • Paid Help
  • Data Management
  • Empirical Models using Stata®
  • Paid Help – FAQs
  • Paid Help | Pricing
  • Privacy

Recent Projects

  • Conditional Beta using MGARCH Approach
  • Returns to New IPOs
  • Trading frequency | Price Impact
  • Measuring Financial Statement Comparability
  • Expected Idiosyncratic Skewness and Stock Returns
  • Absolute Strength Momentum

Contact Info

Email: attaullah.shah@imsciences.edu.pk

Copyright 2012 - 2020 Attaullah Shah | All Rights Reserved
FacebookTwitterInstagramPinterest
Page load link
Go to Top