How do I reference series stored in a hash in LINREG cards?

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
macro
Posts: 70
Joined: Thu Jul 16, 2015 3:01 pm

How do I reference series stored in a hash in LINREG cards?

Unread post by macro »

I have code that allows me to toggle between different regression models. Here is an example, where "use_logs" is the toggle:

Code: Select all

calendar(q) 1947 1
allocate 50 2015:2

compute use_logs = 1

open data nipa.csv
    data(format=cdf, org=columns, dateform="m/d/y") 1947:1 2015:2 gdp cons gce gov nx unemp
close data

declare hash[series] vars
set vars("unemp") = unemp

dofor s = gdp cons gce gov
    compute [label] lbl = "L" + %l(s)
    set %s(lbl) = log(s{0})
    
    * If use_logs == 1, assign vars("gdp") = lgdp
    * Otherwise, assign vars("gdp") = gdp
    if use_logs == 1 {
        set vars(%l(s)) = %s(lbl)
        labels vars(%l(s))
        # lbl
    }
    else {
        set vars(%l(s)) = s
        labels vars(%l(s))
        # %l(s)
    }
end dofor s

declare string str
dofor str = "gdp" "cons" "gce" "gov"
    linreg(print) vars(&str)
    # unemp{1 to 2}
end dofor str

linreg(print) lgov
# %rladdlaglist(%rlempty(),unemp,||1,2,3,4||)

linreg(print) lgov
# %rladdlaglist(%rlempty(),vars("unemp"),||1,2,3,4||)
Everything works as I would expect, except for the final statement:

Code: Select all

linreg(print) lgov
# %rladdlaglist(%rlempty(),vars("unemp"),||1,2,3,4||)
Instead of including four lags of unemployment, RATS includes four constants:

Code: Select all

Linear Regression - Estimation by Least Squares
Dependent Variable LGOV
Quarterly Data From 1947:01 To 2015:02
Usable Observations                       274
Degrees of Freedom                        273
Centered R^2                       -0.0000000
R-Bar^2                            -0.0000000
Uncentered R^2                      0.9959224
Mean of Dependent Variable       7.3969521777
Std Error of Dependent Variable  0.4741704417
Standard Error of Estimate       0.4741704417
Sum of Squared Residuals         61.380666936
Log Likelihood                      -183.8326
Durbin-Watson Statistic           1.4445e-003

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  Constant{1}                  7.3969521777 0.0286456840    258.22222  0.00000000
2.  Constant{2}                  0.0000000000 0.0000000000      0.00000  0.00000000
3.  Constant{3}                  0.0000000000 0.0000000000      0.00000  0.00000000
4.  Constant{4}                  0.0000000000 0.0000000000      0.00000  0.00000000
I realize this is a simple example, but I'm trying to figure out how to refer to a series stored in a hash within the cards of a linear regression. I also tried

Code: Select all

linreg(print) lgov
# vars("unemp"){1 to 4}
but that also includes four constant terms, not four lags of unemployment.
Attachments
nipa.csv
(12.6 KiB) Downloaded 1140 times
macro
Posts: 70
Joined: Thu Jul 16, 2015 3:01 pm

Re: How do I reference series stored in a hash in LINREG car

Unread post by macro »

I should add that I'm currently using RATS v8.3, but hopefully we'll get v9 soon. Is it possible to achieve this in either of these versions?
macro
Posts: 70
Joined: Thu Jul 16, 2015 3:01 pm

Re: How do I reference series stored in a hash in LINREG car

Unread post by macro »

I also tried using a type declaration in the LINREG statement, e.g.

Code: Select all

linreg(print) lgov
# %rladdlaglist(%rlempty(),[series] vars("unemp"),||1,2,3,4||)
but this also has no effect, and the regression still runs with four constant terms instead of four lags of unemployment.

Is there anything else I should try to get this to work? This is a major sticking point in the program I'm trying to develop.
Post Reply