Hi Theodoros,
did you check my RollingStats package?
https://gretl.sourceforge.net/current_fnfiles/RollingStats.gfn
In the sample script you find examples on how to do this?
Best
Artur
Am 12.11.24 um 19:25 schrieb Theodoros Panagiotidis:
> 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
> ols y const x # Run OLS on the defined sample
>
> # Store results
> coef_x[i] = $coeff(x) # Store the coefficient for x
> intercept[i] = $coeff(const) # Store the intercept (constant term)
> endloop
>
> # Reset the sample to full range after the loop
> sample 1 $nobs # Reset to full sample
>
> # Plot results or save as desired
> gnuplot coef_x intercept --with-lines --time-series
>