5. Optimization
①technique(str):其中str的可选项包括map、lsmr、lsqr和gt,其中map是默认选项。
technique(map)通过MAP方法将变量的影响分离出来,但目前不适用于个人和群体固定效果。是快速稳定的选项。
technique(map) (default)will partial out variables using the "method of alternating projections" (MAP) in any of its variants. MAP currently does not work with individual & group fixed effects. Fast and stable option
technique(lsmr) 使用 Fong 和 Saunders LSMR 算法,适用于个体固定效应。更多信息参考文章P:\TEX\SISC\33-5\79687\79687.dvi (stanford.edu)
technique(lsmr) use the Fong and Saunders LSMR algorithm. Recommended (default) technique when working with individual fixed effects. LSMR is an iterative method for solving sparse least-squares problems; analytically equivalent to the MINRES method on the normal equations. For more information on the algorithm, please reference the paper P:\TEX\SISC\33-5\79687\79687.dvi (stanford.edu)
technique(lsqr) 使用 Paige 和 Saunders LSQR 算法。处理个体固定效应的另一种技术。更多信息参考
https://web.stanford.edu/group/SOL/software/lsqr/lsqr-toms82a.pdf
technique(lsqr) use Paige and Saunders LSQR algorithm. Alternative technique when working with individual fixed effects. LSQR is an iterative method for solving sparse least-squares problems; analytically equivalent to conjugate gradient method on the normal equations. Fast, but less precise than LSMR at default tolerance (1e-8).For more information on the algorithm, please reference the paper
https://web.stanford.edu/group/SOL/software/lsqr/lsqr-toms82a.pdf
technique(gt)目前已禁用。
technique(gt) variation of Spielman et al's graph-theoretical (GT) approach (using a spectral sparsification of graphs); currently disabled
②acceleration(str):与tech(map)相关。允许不同的加速技术,选项包括none,steep_descent,aitken和conjugate_gradient。
acceleration(str) Relevant for tech(map). Allows for different acceleration techniques, from the simplest case of no acceleration (none), to steep descent (steep_descent or sd), Aitken (aitken), and finally Conjugate Gradient (conjugate_gradient or cg).
Note: Each acceleration is just a plug-in Mata function, so a larger number of acceleration techniques are available, albeit undocumented (and slower).
③transform(str)支持不同的可选项替换,传统方式是kaczmarz,更稳定的选项是cimmino和symmetric_kaczmarz。
transform(str) allows for different "alternating projection" transforms. The classical transform is Kaczmarz (kaczmarz), and more stable alternatives are Cimmino (cimmino) and Symmetric Kaczmarz (symmetric_kaczmarz)
要注意,不同的加速方式通常更适合某些变换。例如,不要将共轭梯度与普通的 Kaczmarz 一起使用,否则不能收敛。
Note: The default acceleration is Conjugate Gradient and the default transform is Symmetric Kaczmarz. Be wary that different accelerations often work better with certain transforms. For instance, do not use conjugate gradient with plain Kaczmarz, as it will not converge (this is because CG requires a symmetric operator in order to converge, and plain Kaczmarz is not symmetric).
④preconditioner(str),选择预调节器,以更好地收敛。选项:none、diagonal和block_diagonal (默认)。
preconditioner(str) LSMR/LSQR require a good preconditioner in order to converge efficiently and in few iterations. reghfe currently supports right-preconditioners of the following types: none, diagonal, and block_diagonal (default).
⑤prune(str)目前已禁用。
prune vertices of degree-1; acts as a preconditioner that is useful if the underlying network is very sparse; currently disabled
⑥tolerance(#)指定收敛的容忍度标准,默认值为1e-8。通常,高容忍度(1e-8 至 1e-14)可以得到更准确的结果,但速度较慢,高于1e-14的容忍度可能不会收敛。同样,低容忍度(1e-7、1e-6 等)得到结果的速度更快,但可能不准确。低于1e-6的容忍度同样不建议,因为迭代可能停止得太快,导致回报的结果不准确,但对于非常大的数据集,在初步计算时使用低容忍度有时很有用。
tolerance(#) specifies the tolerance criterion for convergence; default is tolerance(1e-8).In general, high tolerances (1e-8 to 1e-14) return more accurate results, but more slowly. Similarly, low tolerances (1e-7, 1e-6, ...) return faster but potentially inaccurate results.
Note that tolerances higher than 1e-14 might be problematic, not just due to speed, but because they approach the limit of the computer precision (1e-16). Thus, using e.g. tol(1e15) might not converge, or take an inordinate amount of time to do so.
At the other end, low tolerances (below 1e-6) are not generally recommended, as the iteration might have been stopped too soon, and thus the reported estimates might be incorrect. However, with very large datasets, it is sometimes useful to use low tolerances when running preliminary estimates.
注意:使用迭代方法(即reghdfe使用的那些)比使用直接方法(即回归使用的方法)检测完全共线的因变量更困难。想要找到未被识别的完全共线因变量,需要寻找极高的标准误差。在这种情况下,考虑使用更高的容忍度。
Note: detecting perfectly collinear regressors is more difficult with iterative methods (i.e. those used by reghdfe) than with direct methods (i.e. those used by regress). To spot perfectly collinear regressors that were not dropped, look for extremely high standard errors. In this case, consider using higher tolerances.
提醒:当模型中异质性的斜率没有和异质性的截距项搭配使用时,收敛性会相当差,强烈建议使用更高的容忍度(即高于默认值)。换句话说,var1##c.var2比var1#c.var2更容易收敛,后者可能需要更高的容忍度。
Warning: when absorbing heterogeneous slopes without the accompanying heterogeneous intercepts, convergence is quite poor and a higher tolerance is strongly suggested (i.e. higher than the default). In other words, an absvar of var1##c.var2 converges easily, but an absvar of var1#c.var2 will converge slowly and may require a higher tolerance.
⑦iterations(#)指定最大迭代次数,默认值为迭代16000次,即iterations(16000)。设置iterations(.)表示程序一直运行到收敛为止。
iterations(#) specifies the maximum number of iterations; the default is iterations(16000); set it to missing (.) to run forever until convergence.
⑧nosample不会创建e(样本),从而节省一些空间和速度。
nosample will not create e(sample), saving some space and speed.
6. Parallel execution
parallel(#1, cores(#2) options)参阅网站
https://github.com/gvegayon/parallel。parallel()只会在某些情况下加快执行速度。首先,数据集需要足够大,并且/或者部分输出过程需要足够大。其次,如果计算机只有一个或几个内核,或者内存有限,则可能无法实现显著加速。
parallel(#1, cores(#2) options) runs the partialling-out step in #1 separate Stata processeses, each using #2 cores. This option requires the parallel package (see website). There are several additional suboptions, discussed here.
Note that parallel() will only speed up execution in certain cases. First, the dataset needs to be large enough, and/or the partialling-out process needs to be slow enough, that the overhead of opening separate Stata instances will be worth it. Second, if the computer has only one or a few cores, or limited memory, it might not be able to achieve significant speedups.
7. Memory Usage
①poolize(#)默认设置是poolize(10)。数值越大,速度越快,但可能会导致内存不足导致报错。在这种情况下,设置poolize(1)。
poolsize(#) Number of variables that are pooled together into a matrix that will then be transformed. The default is to pool variables in groups of 10. Larger groups are faster with more than one processor, but may cause out-of-memory errors. In that case, set poolsize to 1.
②compact 在每一步中保留数据集并尽可能多地删除变量。
compact preserve the dataset and drop variables as much as possible on every step
8. Reporting
①level(#) 设置置信区间,默认为level(95)。
level(#) sets confidence level; default is level(95); see [R] Estimation options
②display_options: noci, nopvalues, noomitted, vsquish, noemptycells, baselevels, allbaselevels, nofvlabel, fvwrap(#), fvwrapon(style), cformat(%fmt), pformat(%fmt), sformat(%fmt), and nolstretch; see [R] Estimation options.
③noheader 在输出内容的顶部不显示汇总统计表,仅显示系数表。
noheader suppresses the display of the table of summary statistics at the top of the output; only the coefficient table is displayed.This option is often used in programs and ado-files.
④notable 不显示系数表。
notable suppresses display of the coefficient table.
⑤nofootnote 不显示固定效应的脚注表。
nofootnote suppresses display of the footnote table that lists the absorbed fixed effects, including the number of categories/levels of each fixed effect, redundant categories (collinear or otherwise not counted when computing degrees-of-freedom), and the difference between both.
⑥noconstant 不显示常数项。不影响估计结果。
noconstant suppresses display of the _cons row in the main table. No results or computations change, this is merely a cosmetic option
9. Diagnostic
①verbose(#) 输出调试信息。可能值为0、1、2、3和4。对调试最有用的是3,最简单的报告是1。
verbose(#) orders the command to print debugging information. Possible values are 0 (none), 1 (some information), 2 (even more), 3 (adds dots for each iteration, and reports parsing details), 4 (adds details for every iteration step). For debugging, the most useful value is 3. For simple status reports, set verbose to 1.
②timeit显示不同估计步骤的时间。大多数时间通常花在三个步骤上:map_precompute(),map_solve()和回归步骤。
timeit shows the elapsed time at different steps of the estimation. Most time is usually spent on three steps: map_precompute(), map_solve() and the regression step.
③version(#) 汇报所安装的reghdfe版本。
version(#) reghdfe has had so far two large rewrites, from version 3 to 4, and version 5 to version 6.Because the rewrites might have removed certain features (e.g. IV/2SLS was available in version 3 but moved to ivreghdfe on version 4), this option allows you to run the previous versions without having to install them (they are already included in reghdfe installation).
To use them, just add the options version(3) or version(5). You can check their respective help files here: reghdfe3, reghdfe5. This option is also useful when replicating older papers, or to verify the correctness of estimates under the latest version. Tip:To avoid the warning text in red, you can add the undocumented nowarn option.