Skip to content

Commit c328587

Browse files
authored
Merge pull request #188 from pedrovma/main
Fix bug in slx_vars in set_endog
2 parents 313d45f + bed14d1 commit c328587

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

spreg/utils.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -697,21 +697,24 @@ def set_endog(y, x, w, yend, q, w_lags, lag_q, slx_lags=0, slx_vars="all"):
697697
yend = yl
698698
else:
699699
raise Exception("invalid value passed to yend")
700+
700701
if slx_lags == 0:
701702
return yend, q
702-
else: # ajdust returned lag_x here using slx_vars
703-
if (isinstance(slx_vars,list)): # slx_vars has True,False
704-
if len(slx_vars) != x.shape[1] :
705-
raise Exception("slx_vars incompatible with x column dimensions")
706-
else: # use slx_vars to extract proper columns
707-
vv = slx_vars @ slx_lags
708-
lag_x = lag_x[:,vv]
703+
else:
704+
if isinstance(slx_vars, str) and slx_vars.lower() == "all":
709705
return yend, q, lag_x
710-
else: # slx_vars is "All"
706+
else:
707+
if isinstance(slx_vars, str):
708+
raise ValueError(f"Invalid string input: '{slx_vars}'. Did you mean 'all'?")
709+
710+
slx_vars = np.array(slx_vars)
711+
if slx_vars.shape[0] != x.shape[1]:
712+
raise Exception("slx_vars incompatible with x column dimensions")
713+
714+
lag_x = lag_x[:, slx_vars]
711715
return yend, q, lag_x
712716

713717

714-
715718
def set_endog_sparse(y, x, w, yend, q, w_lags, lag_q):
716719
"""
717720
Same as set_endog, but with a sparse object passed as weights instead of W object.

0 commit comments

Comments
 (0)