Characteristic (sfi.Characteristic)¶
-
class
sfi.
Characteristic
¶ This class provides access to Stata characteristics.
Method Summary
getDtaChar
(name)Get a characteristic for the current dataset. getVariableChar
(var, name)Get a characteristic for a variable in the current dataset. setDtaChar
(name, value)Set a characteristic for the current dataset. setVariableChar
(var, name, value)Set a characteristic for a variable in the current dataset. Method Detail
-
static
getDtaChar
(name)¶ Get a characteristic for the current dataset.
Parameters: name (str) – The name of the characteristic to retrieve. Returns: Value of the characteristic. Returns an empty string if the characteristic is not found. Return type: str
-
static
getVariableChar
(var, name)¶ Get a characteristic for a variable in the current dataset.
Parameters: - var (str or int) – Name or index of the variable.
- name (str) – Name of the characteristic.
Returns: Value of the characteristic. Returns an empty string if the characteristic is not found.
Return type: str
Raises: ValueError
– If var is not found or is out of range.
-
static
setDtaChar
(name, value)¶ Set a characteristic for the current dataset.
Parameters: - name (str) – Name of the characteristic.
- value (str) – Value to set.
-
static
Examples¶
The following provides a few quick examples illustrating how to use this class:
>>> from sfi import Characteristic
>>> stata: sysuse auto, clear
(1978 Automobile Data)
>>> Characteristic.setDtaChar('one', 'this is char named one of _dta')
>>> Characteristic.setDtaChar('two', 'this is char named two of _dta')
>>> Characteristic.setVariableChar('mpg', 'one', 'this is char named one of mpg')
>>> Characteristic.setVariableChar('mpg', 'two', 'this is char named two of mpg')
>>> stata: char list
_dta[two]: this is char named two of _dta
_dta[one]: this is char named one of _dta
_dta[note0]: 1
_dta[note1]: from Consumer Reports with permission
mpg[two]: this is char named two of mpg
mpg[one]: this is char named one of mpg
>>> Characteristic.getDtaChar('one')
'this is char named one of _dta'
>>> Characteristic.getDtaChar('two')
'this is char named two of _dta'
>>> Characteristic.getVariableChar('mpg', 'one')
'this is char named one of mpg'
>>> Characteristic.getVariableChar('mpg', 'two')
'this is char named two of mpg'