Scalar (sfi.Scalar)¶
-
class
sfi.
Scalar
¶ This class provides access to Stata scalars.
Method Summary
getString
(name)Get the contents of a Stata string scalar. getValue
(name)Get the value of a Stata numeric scalar. setString
(name, value)Set the contents of a Stata string scalar. setValue
(name, value[, vtype])Set the value of a Stata numeric scalar. Method Detail
-
static
getString
(name)¶ Get the contents of a Stata string scalar.
Parameters: name (str) – Name of the scalar. It can be one of the following:
- global scalar such as “myname”
- c() scalar such as “c(current_date)”
Returns: Value of the scalar. Returns an empty string if the scalar is not found or if the scalar is marked as binary. Return type: str
-
static
getValue
(name)¶ Get the value of a Stata numeric scalar.
Parameters: name (str) – Name of the scalar. It can be one of the following:
- global scalar such as “myname”
- return() scalar such as “return(retval)”
- r() scalar such as “r(mean)”
- e() scalar such as “e(N)”
- c() scalar such as “c(level)”
Returns: Value of the scalar. Return type: float
-
static
setString
(name, value)¶ Set the contents of a Stata string scalar. If necessary, the scalar will be created.
Parameters: - name (str) – Name of the scalar.
- value (str) – Value to store in the scalar.
-
static
setValue
(name, value, vtype='visible')¶ Set the value of a Stata numeric scalar. If necessary, the scalar will be created.
Parameters: - name (str) –
Name of the scalar. It can be one of the following:
- global scalar such as “myname”
- return() scalar such as “return(retval)”
- r() scalar such as “r(mean)”
- e() scalar such as “e(N)”
- value (float) – Value to store in the scalar.
- vtype ({'visible', 'hidden', 'historical'}, optional) – If the scalar is either a return(), r(), or e() scalar, vtype sets whether the return value is visible, hidden, or historical. This parameter is ignored when the scalar is a global scalar. Default is ‘visible’.
- name (str) –
-
static
Examples¶
The following provides a few quick examples illustrating how to use this class:
>>> from sfi import Scalar
>>> stata: sysuse auto, clear
(1978 Automobile Data)
>>> stata: regress mpg weight foreign
Source | SS df MS Number of obs = 74
-------------+---------------------------------- F(2, 71) = 69.75
Model | 1619.2877 2 809.643849 Prob > F = 0.0000
Residual | 824.171761 71 11.608053 R-squared = 0.6627
-------------+---------------------------------- Adj R-squared = 0.6532
Total | 2443.45946 73 33.4720474 Root MSE = 3.4071
------------------------------------------------------------------------------
mpg | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
weight | -.0065879 .0006371 -10.34 0.000 -.0078583 -.0053175
foreign | -1.650029 1.075994 -1.53 0.130 -3.7955 .4954422
_cons | 41.6797 2.165547 19.25 0.000 37.36172 45.99768
------------------------------------------------------------------------------
>>> stata: ereturn list
scalars:
e(N) = 74
e(df_m) = 2
e(df_r) = 71
e(F) = 69.74846262000308
e(r2) = .6627029116028815
e(rmse) = 3.407059285651584
e(mss) = 1619.287698167387
e(rss) = 824.1717612920727
e(r2_a) = .6532015851691599
e(ll) = -194.1830643938065
e(ll_0) = -234.3943376482347
e(rank) = 3
macros:
e(cmdline) : "regress mpg weight foreign"
e(title) : "Linear regression"
e(marginsok) : "XB default"
e(vce) : "ols"
e(depvar) : "mpg"
e(cmd) : "regress"
e(properties) : "b V"
e(predict) : "regres_p"
e(model) : "ols"
e(estat_cmd) : "regress_estat"
matrices:
e(b) : 1 x 3
e(V) : 3 x 3
functions:
e(sample)
>>> Scalar.getValue('e(r2_a)')
0.6532015851691599
>>> Scalar.setValue('e(r2_a)', 0.3)
>>> Scalar.getValue('e(r2_a)')
0.3