We wanted to create an do-file for a coefficient-estimation for the previos 36 months for each fund and then calculate a 12-month ahead estimate for alpha , but when we want to apply this do file to our dataset we always get the error message 'invalid syntax' r(198), but stata does not specify where our problem is.
//load dataset
gen SPret = benchmark - rf
//generate variables for results with momentum
gen alpha = .
gen beta_SPret = .
gen beta_smb = .
gen beta_hml = .
gen beta_mom = .
gen r2 = .
//generate variables for results (without momentum)
gen alpha_wom = .
gen beta_SPret_wom = .
gen beta_smb_wom = .
gen beta_hml_wom = .
gen r2_wom = .
//begin loop
//create group identifier with variable code
egen id = group(name)
sort name year month
sum id
local max `r(max)'
forvalues i = 1/`max' {
foreach id == `i' {
local y = min(calmt) //create local min of calmt to know where to start
local z = max(calmt) //create local max to identify ending point
di in red "`c(current_time)': @id: `i'" //show loop results
sum id if id == `i' // Calculate the sum of observations for each funds
if `r(N)' > 47 { // There have to be at least 47 months calmt observations, because the coefficients are calculated over a period of 36 months and then an alpha is calculated 12 months ahead
rolling _b, start(y) window(36) end(z-12) saving(betas_m) stepsize(1) : reg mgret SPret smb hml mom
replace alpha = _b[_cons] if id == `i'
replace beta_SPret = _b[SPret] if id == `i'
replace beta_smb = _b[smb] if id == `i'
replace beta_hml = _b[hml] if id == `i'
replace beta_mom = _b[mom] if id == `i'
replace r2 = e(r2) if id == `i'
}
}
}
di in red "`c(current_time)': @id: `i'" //show loop results
sort name year month
sum id
local max `r(max)'
forvalues i = 1/`max' {
foreach id == `i' {
local y = min(calmt) //create local min of calmt to know where to start
local z = max(calmt) //create local max to identify ending point
di in red "`c(current_time)': @id: `i'" //show loop results
if `r(N)' > 47 {
//regression without momentum
rolling _b, start(y) window(36) end(z-12) saving(betas_wom) stepsize(1): reg mgret SPret smb hml
replace alpha = _b[_cons] if id == `i'
replace beta_SPret = _b[SPret] if id == `i'
replace beta_smb = _b[smb] if id == `i'
replace beta_hml = _b[hml] if id == `i'
replace r2_wom = e(r2_wom) if id == `i'
}
}
}
}
Related Posts with Invalid Syntax
xtmixed difference between main model and postestimation (pwcompare) results (with and without interaction effect)Hi there - sorry if this is a very silly question, but I was a little confused. Simplifed code and m…
2x7 table differencesSo I have 2 independent variables and 1 dependent category with 7 variables. Fishers exact tells me …
Tabulating and dropping grouped dataHi, I have a dataset based on a survey where each individual is given a unique id and has several r…
Merging two datasetsI have two datasets that needs to be merged. But one row in the main dataset is representing multipl…
Combining meglm and svy: error messageOur goal is to build a three-level hierarchical linear model based on complex survey design in Stata…
Subscribe to:
Post Comments (Atom)
0 Response to Invalid Syntax
Post a Comment