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
Handling of out of range valuesDear All, I've just found that the following code does not produce an error, while I anticipated it…
Stack bar graph with cumulative on secondary axis as line graph Array I want to make the following graph using Stata. Could anyone please help …
Long form dataHi I have data in Stata I want to convert this into long formate, please clear input LATNUM LONGN…
Incomplete Data Pull using georoute CommandI am calculating driving distances using the georoute command with decimal degree coordinates. When …
Fixed Effects Categorical outcome and independent variable modeling - repeated cross sectionHello all. Stata/MP 17. I have researched in here and elsewhere, and found some useful info and I am…
Subscribe to:
Post Comments (Atom)
0 Response to Invalid Syntax
Post a Comment