I am not sure whether the following code works best for the purpose. Based on my data, it takes around two days to run from 2010-2019. I also intend to run data since 1990s, so it may take several days. I think it is a bit long.
If there is a better way to save time, please let me know and thank you so much.
gen relative_FB_all = .
gen relative_Forecast_horizon_all = .
gen relative_dayElap_all = .
gen relative_forecast_frequency_all = .
gen relative_firm_specific_all = .
gen relative_generic_all = .
gen relative_cos_followed_all = .
gen relative_indus_followed_all = .
gen relative_analyst_broke_all = .
destring gvkey, replace
levelsof fiscal_year, local(years)
foreach year of local years {
levelsof gvkey if fiscal_year == `year', local(companies)
foreach company of local companies {
levelsof analys if fiscal_year ==`year' & gvkey==`company', local(analysts)
foreach analyst of local analysts {
su forecast_bias ///
if analys!=`analyst' & fiscal_year==`year' & gvkey==`company'
replace relative_FB_all=r(mean) ///
if analys!=`analyst' & fiscal_year==`year' & gvkey==`company'
di `year'
di `company'
di `analyst'
}
}
}
Related Posts with simplified code
Store variable names for specific conditionHi all, I wonder if its possible save or store a list of variable names with a specific condition, …
egen newvar = divide(existingvar), by(existingvar2)Hi! I know how to perform : Code: egen v5 = sum(var4), by(var1) var1 var4 v5 1 301 4323 1 4…
Logit model: how to interpret negative AMEs?Dear Statalist, I am using Stata 15.1 with Windows 10. I have a logit model on cross-border deals i…
Creating a new variable by using a string variable in STATAFor example, X is a variable X 123 234 35 67 82 Now the values are saved as strings. If I want to cr…
Endogenous Explanatory Variable in a Multinomial Logit EstimationHi Statalist I am wondering what are the possible options for modelling endogeneity in a multinomia…
Subscribe to:
Post Comments (Atom)
0 Response to simplified code
Post a Comment