Skip to content

Commit

Permalink
Fix several string truncation bugs (Stata 11,12)
Browse files Browse the repository at this point in the history
This commit fixes a bug reported by Tan Ruijie as well as several
related bugs.

On Stata 12 and older, `local var = ...` gets truncated with long
strings.
The solution is to use `local var "..."`
  • Loading branch information
sergiocorreia committed Jul 29, 2015
1 parent 3d628fc commit 7c87214
Show file tree
Hide file tree
Showing 24 changed files with 92 additions and 66 deletions.
8 changes: 4 additions & 4 deletions build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ def zipdir(path, zip):
shutil.copy(os.path.join(source_path, "reghdfe_old_estat.ado"), os.path.join(server_path, "reghdfe_old_estat.ado"))
shutil.copy(os.path.join(source_path, "reghdfe_old_footnote.ado"), os.path.join(server_path, "reghdfe_old_footnote.ado"))

print("Building zip file")
zipf = zipfile.ZipFile('../misc/reghdfe.zip', 'w', zipfile.ZIP_DEFLATED)
zipdir('../package/', zipf)
zipf.close()
# print("Building zip file")
# zipf = zipfile.ZipFile('../misc/reghdfe.zip', 'w', zipfile.ZIP_DEFLATED)
# zipdir('../package/', zipf)
# zipf.close()

# Update version file now that the deed is done
with open(os.path.join(source_path, "version.txt"), 'wb') as fh:
Expand Down
Binary file removed misc/reghdfe.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions package/estfe.ado
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ program define Add, rclass
local indicate_fe `"`indicate_fe' "`fixed_fe'=`fe'""'
}

return local indicate_fe = `"`indicate_fe'"'
return local indicate_fe `"`indicate_fe'"'
end

capture program drop AddOne
Expand Down Expand Up @@ -101,7 +101,7 @@ program define AddOne, eclass

erepost b=`b' V=`V', rename // Minor problem: removes "hidden" attribute
estimates store `model', nocopy
c_local absvars = "`absvars'"
c_local absvars "`absvars'"
end

capture program drop FixAbsvars
Expand Down
14 changes: 7 additions & 7 deletions package/hdfe.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! reghdfe 3.2.2 26jul2015
*! reghdfe 3.2.3 29jul2015
*! Sergio Correia (sergio.correia@duke.edu)


Expand Down Expand Up @@ -2025,8 +2025,8 @@ program define hdfe, eclass
mata: map_ereturn_dof(HDFE_S)
local N_hdfe = e(N_hdfe)
ereturn local cmd = "hdfe"
ereturn local extended_absvars = "`extended_absvars'"
ereturn local absvars = "`original_absvars'"
ereturn local extended_absvars "`extended_absvars'"
ereturn local absvars "`original_absvars'"

* Cleanup
} // cap noi
Expand Down Expand Up @@ -2110,7 +2110,7 @@ end
// -------------------------------------------------------------

program define Version, eclass
local version "3.2.2 26jul2015"
local version "3.2.3 29jul2015"
ereturn clear
di as text "`version'"
ereturn local version "`version'"
Expand Down Expand Up @@ -2249,9 +2249,9 @@ if (!`usecache') {

mata: HDFE_S = map_init() // Reads results from r()
local will_save_fe = `r(will_save_fe)' // Returned from map_init()
local original_absvars = "`r(original_absvars)'"
local extended_absvars = "`r(extended_absvars)'"
local equation_d = "`r(equation_d)'"
local original_absvars "`r(original_absvars)'"
local extended_absvars "`r(extended_absvars)'"
local equation_d "`r(equation_d)'"
}
else {
local will_save_fe 0
Expand Down
2 changes: 1 addition & 1 deletion package/hdfe.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ d KW: within
d
d Requires: Stata version 11.2
d
d Distribution-Date: 20150726
d Distribution-Date: 20150729
d

f hdfe.ado
Expand Down
56 changes: 35 additions & 21 deletions package/reghdfe.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! reghdfe 3.2.2 26jul2015
*! reghdfe 3.2.3 29jul2015
*! Sergio Correia (sergio.correia@duke.edu)


Expand Down Expand Up @@ -2045,7 +2045,7 @@ end
// -------------------------------------------------------------

program define Version, eclass
local version "3.2.2 26jul2015"
local version "3.2.3 29jul2015"
ereturn clear
di as text "`version'"
ereturn local version "`version'"
Expand Down Expand Up @@ -2207,8 +2207,15 @@ if (`timeit') Tic, n(55)
* STAGES LOOPS
foreach stage of local stages {
Assert inlist("`stage'", "none", "iv", "first", "ols", "reduced", "acid")
local lhs_endogvars = cond("`stage'"=="first", "`backup_endogvars'", "<none>")
local i_endogvar = cond("`stage'"=="first", "0", "")
if ("`stage'"=="first") {
local lhs_endogvars "`backup_endogvars'"
local i_endogvar 0
}
else {
local lhs_endogvars "<none>"
local i_endogvar
}

foreach lhs_endogvar of local lhs_endogvars {

if ("`stage'"!="none") {
Expand Down Expand Up @@ -2473,9 +2480,9 @@ if (!`usecache') {

mata: HDFE_S = map_init() // Reads results from r()
local will_save_fe = `r(will_save_fe)' // Returned from map_init()
local original_absvars = "`r(original_absvars)'"
local extended_absvars = "`r(extended_absvars)'"
local equation_d = "`r(equation_d)'"
local original_absvars "`r(original_absvars)'"
local extended_absvars "`r(extended_absvars)'"
local equation_d "`r(equation_d)'"
}
else {
local will_save_fe 0
Expand Down Expand Up @@ -3387,7 +3394,7 @@ program define Wrapper_regress, eclass

local predict = e(predict)
local cmd = e(cmd)
local cmdline = e(cmdline)
local cmdline "`e(cmdline)'"
local title = e(title)

* Fix V
Expand All @@ -3411,7 +3418,7 @@ program define Wrapper_regress, eclass
ereturn local marginsok = "`marginsok'"
ereturn local predict = "`predict'"
ereturn local cmd = "`cmd'"
ereturn local cmdline = "`cmdline'"
ereturn local cmdline `"`cmdline'"'
ereturn local title = "`title'"
ereturn local clustvar = "`clustervars'"
ereturn scalar rmse = `rmse'
Expand All @@ -3435,7 +3442,7 @@ program define RemoveCollinear, rclass
syntax, depvar(varname numeric) [indepvars(varlist numeric) weightexp(string)]

qui _rmcoll `indepvars' `weightexp', forcedrop
local okvars = r(varlist)
local okvars "`r(varlist)'"
if ("`okvars'"==".") local okvars
local df_m : list sizeof okvars

Expand Down Expand Up @@ -3509,7 +3516,7 @@ program define Wrapper_avar, eclass

local predict = e(predict)
local cmd = e(cmd)
local cmdline = e(cmdline)
local cmdline `"`e(cmdline)'"'
local title = e(title)

* Compute the bread of the sandwich inv(X'X/N)
Expand Down Expand Up @@ -3566,7 +3573,7 @@ program define Wrapper_avar, eclass
ereturn local marginsok = "`marginsok'"
ereturn local predict = "`predict'"
ereturn local cmd = "`cmd'"
ereturn local cmdline = "`cmdline'"
ereturn local cmdline `"`cmdline'"'
ereturn local title = "`title'"
ereturn local clustvar = "`clustervars'"

Expand Down Expand Up @@ -3632,7 +3639,7 @@ syntax , depvar(varname) [indepvars(varlist)] ///

local predict = e(predict)
local cmd = e(cmd)
local cmdline = e(cmdline)
local cmdline "`e(cmdline)'"
local title = e(title)

* Compute the bread of the sandwich D := inv(X'X/N)
Expand Down Expand Up @@ -3715,7 +3722,7 @@ syntax , depvar(varname) [indepvars(varlist)] ///
ereturn local marginsok = "`marginsok'"
ereturn local predict = "`predict'"
ereturn local cmd = "`cmd'"
ereturn local cmdline = "`cmdline'"
ereturn local cmdline `"`cmdline'"'
ereturn local title = "`title'"
ereturn scalar rmse = `rmse'
ereturn scalar rss = `rss'
Expand Down Expand Up @@ -4046,9 +4053,9 @@ program define Post, eclass
ereturn local predict = "reghdfe_p"
ereturn local estat_cmd = "reghdfe_estat"
ereturn local footnote = "reghdfe_footnote"
ereturn `hidden' local equation_d = "`equation_d'" // The equation used to construct -d- (used to predict)
ereturn local absvars = "`original_absvars'"
ereturn `hidden' local extended_absvars = "`extended_absvars'"
ereturn `hidden' local equation_d "`equation_d'" // The equation used to construct -d- (used to predict)
ereturn local absvars "`original_absvars'"
ereturn `hidden' local extended_absvars "`extended_absvars'"


ereturn `hidden' local diopts = "`diopts'"
Expand Down Expand Up @@ -4175,7 +4182,7 @@ program define Post, eclass
* List of stored estimates
if ("`e(savestages)'"=="1" & "`e(model)'"=="iv") {
local stages = "`e(stages)'"
local endogvars = e(endogvars)
local endogvars "`e(endogvars)'"
foreach stage of local stages {
if ("`stage'"=="first") {
local i 0
Expand Down Expand Up @@ -4346,7 +4353,7 @@ end
if (`c(version)'>=12) local hidden hidden

if ("`stored'"!="" & "`e(stored_estimates)'"!="" & "`e(stage)'"=="iv") {
local est_list = e(stored_estimates)
local est_list "`e(stored_estimates)'"
tempname hold
estimates store `hold'
foreach est of local est_list {
Expand Down Expand Up @@ -4724,8 +4731,15 @@ program define InnerUseCache, eclass
* STAGES LOOPS
foreach stage of local stages {
Assert inlist("`stage'", "none", "iv", "first", "ols", "reduced", "acid")
local lhs_endogvars = cond("`stage'"=="first", "`backup_endogvars'", "<none>")
local i_endogvar = cond("`stage'"=="first", "0", "")
if ("`stage'"=="first") {
local lhs_endogvars "`backup_endogvars'"
local i_endogvar 0
}
else {
local lhs_endogvars "<none>"
local i_endogvar
}

foreach lhs_endogvar of local lhs_endogvars {

if ("`stage'"!="none") {
Expand Down
2 changes: 1 addition & 1 deletion package/reghdfe.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ d KW: GMM
d
d Requires: Stata version 11.2
d
d Distribution-Date: 20150726
d Distribution-Date: 20150729
d

f reghdfe.ado
Expand Down
2 changes: 1 addition & 1 deletion package/reghdfe_p.ado
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ program define reghdfe_p
}
if ("`option'"=="scores") local option residuals

local fixed_effects = e(absvars)
local fixed_effects "`e(absvars)'"

* Intercept stdp call
if ("`option'"=="stdp") {
Expand Down
4 changes: 2 additions & 2 deletions source/estfe.ado
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ program define Add, rclass
local indicate_fe `"`indicate_fe' "`fixed_fe'=`fe'""'
}

return local indicate_fe = `"`indicate_fe'"'
return local indicate_fe `"`indicate_fe'"'
end

capture program drop AddOne
Expand Down Expand Up @@ -101,7 +101,7 @@ program define AddOne, eclass

erepost b=`b' V=`V', rename // Minor problem: removes "hidden" attribute
estimates store `model', nocopy
c_local absvars = "`absvars'"
c_local absvars "`absvars'"
end

capture program drop FixAbsvars
Expand Down
4 changes: 2 additions & 2 deletions source/hdfe.ado
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ program define hdfe, eclass
mata: map_ereturn_dof(HDFE_S)
local N_hdfe = e(N_hdfe)
ereturn local cmd = "hdfe"
ereturn local extended_absvars = "`extended_absvars'"
ereturn local absvars = "`original_absvars'"
ereturn local extended_absvars "`extended_absvars'"
ereturn local absvars "`original_absvars'"

* Cleanup
} // cap noi
Expand Down
2 changes: 1 addition & 1 deletion source/hdfe.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ d KW: within
d
d Requires: Stata version 11.2
d
d Distribution-Date: 20150726
d Distribution-Date: 20150729
d

f hdfe.ado
Expand Down
11 changes: 9 additions & 2 deletions source/internal/Inner.ado
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,15 @@ if (`timeit') Tic, n(55)
* STAGES LOOPS
foreach stage of local stages {
Assert inlist("`stage'", "none", "iv", "first", "ols", "reduced", "acid")
local lhs_endogvars = cond("`stage'"=="first", "`backup_endogvars'", "<none>")
local i_endogvar = cond("`stage'"=="first", "0", "")
if ("`stage'"=="first") {
local lhs_endogvars "`backup_endogvars'"
local i_endogvar 0
}
else {
local lhs_endogvars "<none>"
local i_endogvar
}

foreach lhs_endogvar of local lhs_endogvars {

if ("`stage'"!="none") {
Expand Down
11 changes: 9 additions & 2 deletions source/internal/InnerUseCache.ado
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,15 @@ program define InnerUseCache, eclass
* STAGES LOOPS
foreach stage of local stages {
Assert inlist("`stage'", "none", "iv", "first", "ols", "reduced", "acid")
local lhs_endogvars = cond("`stage'"=="first", "`backup_endogvars'", "<none>")
local i_endogvar = cond("`stage'"=="first", "0", "")
if ("`stage'"=="first") {
local lhs_endogvars "`backup_endogvars'"
local i_endogvar 0
}
else {
local lhs_endogvars "<none>"
local i_endogvar
}

foreach lhs_endogvar of local lhs_endogvars {

if ("`stage'"!="none") {
Expand Down
6 changes: 3 additions & 3 deletions source/internal/Parse.ado
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ if (!`usecache') {

mata: HDFE_S = map_init() // Reads results from r()
local will_save_fe = `r(will_save_fe)' // Returned from map_init()
local original_absvars = "`r(original_absvars)'"
local extended_absvars = "`r(extended_absvars)'"
local equation_d = "`r(equation_d)'"
local original_absvars "`r(original_absvars)'"
local extended_absvars "`r(extended_absvars)'"
local equation_d "`r(equation_d)'"
}
else {
local will_save_fe 0
Expand Down
8 changes: 4 additions & 4 deletions source/internal/Post.ado
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ program define Post, eclass
ereturn local predict = "reghdfe_p"
ereturn local estat_cmd = "reghdfe_estat"
ereturn local footnote = "reghdfe_footnote"
ereturn `hidden' local equation_d = "`equation_d'" // The equation used to construct -d- (used to predict)
ereturn local absvars = "`original_absvars'"
ereturn `hidden' local extended_absvars = "`extended_absvars'"
ereturn `hidden' local equation_d "`equation_d'" // The equation used to construct -d- (used to predict)
ereturn local absvars "`original_absvars'"
ereturn `hidden' local extended_absvars "`extended_absvars'"


ereturn `hidden' local diopts = "`diopts'"
Expand Down Expand Up @@ -171,7 +171,7 @@ program define Post, eclass
* List of stored estimates
if ("`e(savestages)'"=="1" & "`e(model)'"=="iv") {
local stages = "`e(stages)'"
local endogvars = e(endogvars)
local endogvars "`e(endogvars)'"
foreach stage of local stages {
if ("`stage'"=="first") {
local i 0
Expand Down
2 changes: 1 addition & 1 deletion source/internal/RemoveCollinear.ado
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ program define RemoveCollinear, rclass
syntax, depvar(varname numeric) [indepvars(varlist numeric) weightexp(string)]

qui _rmcoll `indepvars' `weightexp', forcedrop
local okvars = r(varlist)
local okvars "`r(varlist)'"
if ("`okvars'"==".") local okvars
local df_m : list sizeof okvars

Expand Down
2 changes: 1 addition & 1 deletion source/internal/Replay.ado
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cap pr drop Replay
if (`c(version)'>=12) local hidden hidden

if ("`stored'"!="" & "`e(stored_estimates)'"!="" & "`e(stage)'"=="iv") {
local est_list = e(stored_estimates)
local est_list "`e(stored_estimates)'"
tempname hold
estimates store `hold'
foreach est of local est_list {
Expand Down

0 comments on commit 7c87214

Please sign in to comment.