When I do the regression of "abnormal cash flow from operation every year and industry " , only the last step not working, here is the code
Initially
Drop missing values for the variables in equation 1 of the tutorial
------------------------------------------------------------------------------*/
drop if missing(cfo_at)
drop if missing(one_at)
drop if missing(sales_at)
drop if missing(deltasales_at)
/*------------------------------------------------------------------------------
STEP A
Drop regulated industries & banks and financial institutions
------------------------------------------------------------------------------*/
// Drop regulated industries
destring sic, replace // Transform sic codes to numeric format
drop if inrange(sic,4400,5000) // Drop sic codes between 4400 and 5000
// Drop banks and financial institutions
drop if inrange(sic,6000,6500) // Drop sic codes between 6000 and 6500
/*------------------------------------------------------------------------------
STEP B
Keep only more than 15 observations per industry-year group
------------------------------------------------------------------------------*/
tostring sic, replace // Transform sic codes to string format
gen sic2=substr(sic,1,2)
destring sic2, replace sic2: all characters numeric; replaced as byte
drop if missing(sic2) (0 observations deleted)
egen sic2id = group(sic2 fyear) // Create unique identifier for year-industry group
egen count = count(sic2id), by(sic2id) // Count the nr of firms within year-industry group
keep if count >= 15 // Keep firms with more than 15 firms in year-industry group
/*------------------------------------------------------------------------------
STEP C
Calculating the Abnormal CFO per year & industry
------------------------------------------------------------------------------*/
set more off
gen ABN_CFO = . // Abnormal CFO. First you create an empty variable. This will be filled in.
drop sic2id
egen sic2id = group(sic2 fyear) // Create unique identifier for year-industry group
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
sic2id | 61,671 448.1137 251.5735 1 900
.
local max=r(max)
only this part below cannot working , or it shows nothing just like this
forvalues i = 1/`max' {
di "Busy with regression " `i' " of " `max'
qui reg cfo_at one_at sales_at deltasales_at if sic2id == `i'
qui predict res if sic2id == `i', res
qui replace ABN_CFO = res if sic2id == `i'
qui drop res
}
Initially
Drop missing values for the variables in equation 1 of the tutorial
------------------------------------------------------------------------------*/
drop if missing(cfo_at)
drop if missing(one_at)
drop if missing(sales_at)
drop if missing(deltasales_at)
/*------------------------------------------------------------------------------
STEP A
Drop regulated industries & banks and financial institutions
------------------------------------------------------------------------------*/
// Drop regulated industries
destring sic, replace // Transform sic codes to numeric format
drop if inrange(sic,4400,5000) // Drop sic codes between 4400 and 5000
// Drop banks and financial institutions
drop if inrange(sic,6000,6500) // Drop sic codes between 6000 and 6500
/*------------------------------------------------------------------------------
STEP B
Keep only more than 15 observations per industry-year group
------------------------------------------------------------------------------*/
tostring sic, replace // Transform sic codes to string format
gen sic2=substr(sic,1,2)
destring sic2, replace sic2: all characters numeric; replaced as byte
drop if missing(sic2) (0 observations deleted)
egen sic2id = group(sic2 fyear) // Create unique identifier for year-industry group
egen count = count(sic2id), by(sic2id) // Count the nr of firms within year-industry group
keep if count >= 15 // Keep firms with more than 15 firms in year-industry group
/*------------------------------------------------------------------------------
STEP C
Calculating the Abnormal CFO per year & industry
------------------------------------------------------------------------------*/
set more off
gen ABN_CFO = . // Abnormal CFO. First you create an empty variable. This will be filled in.
drop sic2id
egen sic2id = group(sic2 fyear) // Create unique identifier for year-industry group
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
sic2id | 61,671 448.1137 251.5735 1 900
.
local max=r(max)
only this part below cannot working , or it shows nothing just like this
forvalues i = 1/`max' {
di "Busy with regression " `i' " of " `max'
qui reg cfo_at one_at sales_at deltasales_at if sic2id == `i'
qui predict res if sic2id == `i', res
qui replace ABN_CFO = res if sic2id == `i'
qui drop res
}
Comment