On Tue, Nov 12, 2024 at 1:25 PM Theodoros Panagiotidis
<tpanag(a)uom.edu.gr> wrote:
Dear All,
I am trying to write script for running OLS and then plotting the coefficients
# Define your sample and dataset
open capm.gdt # Replace with your dataset file
# Define the rolling window size
scalar window_size = 50 # Set the size of the rolling window (e.g., 60 periods)
# Define the variable names
series y = ERFORD # Replace with your dependent variable
series x = ERSANDP # Replace with your independent variable
# Initialize series to store rolling estimates
series coef_x = NA # Stores coefficient for x
series intercept = NA # Stores intercept (constant term)
# Run rolling regression
loop i = window_size .. $nobs # Loop from the end of the initial window to the last
observation
scalar start = i - window_size + 1 # Calculate the starting point of the window
sample start i # Set the sample range for the current rolling window
The gretl command you want here is "smpl".
Allin Cottrell