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
ppml_panel_sg and r(3203)Hello, I am analyzing the impact of tariffs on trade using ppml_panel_sg, and an r(3203) error some…
Question on rank-ordered probit choice model (cmroprobit)Dear Stata users, I am aiming to run a Rank-ordered probit choice model (cmroprobit) in Stata. My d…
Plotting estimates from -ir- and -iri-Dear Statalisters, Is there a way to plot the IRR and 95%CI after using either Code: ir or Code: …
Losing data when controlling for variables, and how to decide on best model?Hi all I've a trying to estimate the effect of 'economic equality' (X) on whether you want to have …
Dummies on filter events scores and frequency Hello stata users, I am having a panel of groups and need to filter them to positive and not posi…
Subscribe to:
Post Comments (Atom)
0 Response to Invalid Syntax
Post a Comment