pythongis.vector.fileformats.thirdparty.stata_dta.stata_dta module
Functions
def display_diff(
dta1, dta2, all_data=False)
Display summary of differences between two Dta objects.
Parameters
dta1 : Dta instance dta2 : Dta instance all_data : bool (or coercible to bool), optional Specify that all data values should be checked for equality, rather than stopping at first inequality. Default value is False.
Returns
None
Side effects
Displays summary of differences.
def open_dta(
address)
Open any recent version dta file (versions 114, 115, 117) .
Parameters
Address of file, including file name and ".dta".
Returns
Instance of sub-class of Dta, depending on dta file.
Classes
class Dta
A Python parent class for Stata datasets. Sub-classes implement methods for particular versions.
Ancestors (in MRO)
Methods
def __init__(
self, *args, **kwargs)
Initialize Dta object.
Dta objects can be created - from file, - from an iterable of values (as in a list of lists, with one sub-list per observation), - by subscripting an existing Dta (usually done with subscripting syntax like data[::2, (0,4,8)] ), or - by converting one sub-type of Dta to another (for example, converting from version 115 to 117 by converting a Dta115 instance to a Dta117 instance).
New from file
Parameters
address : str Address of dta file, including file name and ".dta".
Example
Dta115("path/to/some_dta_v115.dta") Dta117("path/to/some_dta_v117.dta")
if uncertain of version, open_dta() can open 114, 115, or 117
open_dta("recent_version.dta")
Side effects
If the data set has a label, the label will be printed.
New from iterable
Parameters
varvals : iterable Values to compress : bool (or coercible to bool), optional This sets the default type to attempt to assign to a data variable as byte if compress=True, or float if compress=False. Default type is overridden as necessary. Using compress=True can result in smaller files. Default value is True. single_row : bool (or coercible to bool), optional The code tries to be helpful with inputs. The correct way to specify a single row data set is with a non-string iterable within another iterable, as in ((0,1,2,3)) or [[0,1,2,3]]. With single_row=True, a single row can be specified as, for example, just (0,1,2,3) or [0,1,2,3]. (Don't combine ((0,1,2,3)) with single_row=True.) Default value is False.
Example
v = [[0.0, 0.1, 0.2],[1.0, 1.1, 1.2],[2.0,2.1,2.2]] Dta117(v)
Subscripting a Dta instance (usually used indirectly)
Parameters
old_dta : Dta instance
sel_rows : iterable of int, optional
The rows (observations) to be selected from the old_dta
.
Defaults to all observations.
sel_cols : iterable of int, optional
The cols (data variables) to be selected from the old_dta
.
Defaults to all variables.
Example
take even-numbered observations and variables 0, 4, 8
smaller_dta = some_dta[::2, (0,4,8)]
Converting a Dta instance
Parameters
old_dta : Dta instance
sel_rows : iterable of int, optional
The rows (observations) to be selected from the old_dta
.
Defaults to all observations.
sel_cols : iterable of int, optional
The cols (data variables) to be selected from the old_dta
.
Defaults to all variables.
Example
open a version 115 file
dta115 = open_dta("some_dta_v115.dta")
convert to version 117
dta117 = Dta117(dta115)
Side effects
Data may be changed or variables dropped if converting from a more permissive format to a more restrictive one.
Returns
All examples above return an instance of a Dta sub-class.
Side effects
Initializes Dta object.
def append_obs(
self, value)
Append observations to the end of the dataset.
Parameters
value : iterable Should be an iterable of iterables, one sub-iterable per observation. The observations should contain as many values as there are variables in the data set, and the values should have correct type.
Returns
None
Side effects
Creates new observations in the data set, and inputs the given values into those observations.
def append_var(
self, name, values, st_type=None, compress=True)
def check(
self, version=None)
Determine whether saved data set would conform to limits of given Stata version. (Not .dta version.)
See -help limits- in Stata for more info.
Parameters
version : int, optional Specify a Stata version to check against. Default is to check against Stata version 13.
Returns
None
Side effects
Display summary of limits violations, if any.
def clonevar(
self, oldname, newname)
Create a data variable into a new variable.
New data variable will have the same data values, display format, labels, value labels, notes, and characteristics.
Parameters
oldname : str Single variable name (abbreviation allowed if unambiguous). newname : str New variable name.
Returns
None
Side effects
Creates new variable. Copies data values, display format, labels, value labels, notes, and characteristics.
def copy(
self)
Create a copy of the current Dta instance.
Returns
Dta instance
def describe(
self, simple=False, short=False, fullnames=False, numbers=False, varlist=False)
Display a description of the data set.
Paramters
simple : bool (or coercible to bool), optional
Specify that only a list of variable names be displayed.
No other options may be combined with simple
.
Default value is False.
short : bool (or coercible to bool), optional
Specify that only data set information be displayed.
No information about individual variables will be displayed.
Default value is False.
fullnames : bool (or coercible to bool), optional
Specify that full variable names be used.
Default value is False.
numbers : bool (or coercible to bool), optional
Specify that variables' numbers be included.
Default value is False.
varlist : bool (or coercible to bool), optional
Specify that sortlist and varlist information be saved
(accessible via the return_list
method).
Default value is False.
Returns
None
Side effects
Displays description of data set. Saves associated values,
which can be displayed with return_list
method.
def drop_obs(
self, in_=None, if_=None, all_obs=False)
Drop observations from the data set.
Parameters
in_ : iterable, optional Used to specify observations to drop. Should be an iterable of int. Default is all observations. if_ : function, optional Used to specify observations to drop. Should be a function taking int and returning Boolean (or coercible to Boolean). Default is True for all obs. all_obs : bool or coercible to Boolean, optional Option to drop all observations. Default value is False.
Parameters note
If both in_
and if_
are used, the dropped observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Deletes specified observations.
def drop_var(
self, varnames)
Delete specified variable(s).
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Deletes specified data variables.
def drop_vars(
self, varnames)
Delete specified variable(s).
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Deletes specified data variables.
def format(
self, varnames, fmts)
Set the Stata display format of given data variables.
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous. fmts : str, or iterable of str Can be a str containing one format (e.g. "%9.2f"), a str with multiple formats (e.g. "%9.2f %12s %9.0g"), or an iterable of such str (e.g. ("%9.2f", "%12s", "%9.0g") or ("%9.2f", "%12s %9.0g")).
Notes
If there are fewer formats than varnames, the last format will be repeated. Any extraneous formats will be ignored.
Returns
None
Side effects
Sets the display format of the given data variables.
def get(
self, row, col)
Get single data value.
Parameters
row : integer Row (observation) number of data value. col : integer Column (data variable) number of data value.
Returns
string, numeric, missing value, or binary data value
def index(
self, varname)
Get index of given data variable.
Parameters
varname : str Single varname (abbreviation allowed if unambiguous).
Returns
int Index of variable in data set.
def ismissing(
self, item)
Determine if item qualifies as a numeric missing value.
Parameters
item : None, int, float, or MissingValue instance
Returns
bool
Notes
This function is not meant to be used with non-numeric or non-real values, and will raise an error when given such.
def keep_obs(
self, in_=None, if_=None)
Keep specified observations, remove all others.
Parameters
in_ : iterable, optional Used to specify observations to keep. Should be an iterable of int. Default is all observations. if_ : function, optional Used to specify observations to keep. Should be a function taking int and returning Boolean (or coercible to Boolean). Default is True for all obs.
Parameters note
If both in_
and if_
are used, the kept observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Deletes all observations except those specified.
def keep_var(
self, varnames)
Keep specified variable(s), delete all others.
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Deletes data variables other than those specified.
def keep_vars(
self, varnames)
Keep specified variable(s), delete all others.
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Deletes data variables other than those specified.
def label_copy(
self, orig_name, copy_name, replace=False)
Make a copy of mapping orig_name
with name copy_name
Parameters
orig_name : str
Name of the existing value label mapping.
copy_name : str
Name to be given to the copy.
replace : bool (or coercible to bool), optional
Whether the copy should replace an existing mapping.
Required if a mapping with name copy_name
already exists.
Default value is False.
Returns
None
Side effects
Stores or replaces a copy of a value -> label map in the data set.
def label_data(
self, label)
Add given label to data.
Label will be truncated to 80 characters if necessary.
Parameters
label : str Label should be ascii ('iso-8859-1'). Otherwise, the label will not be saved as intended.
Returns
None
Side effects
Adds label to data.
def label_define(
self, name, mapping, add=False, replace=False, modify=False, fix=True)
Define a VALUE label, a mapping from numeric values to string.
Parameters
name : str
Name of the value label, i.e. name of the mapping.
If a mapping with this name already exists, add
,
replace
, or modify
should be set to True.
mapping : dict
Keys should be int or float, dict values should be str.
add : bool (or coercible to bool), optional
Whether mapping should be added to existing mapping.
An error will be raised if old and new mapping share keys.
Default value is False.
replace : bool (or coercible to bool), optional
Whether mapping should replace existing mapping entirely.
Default value is False.
modify : bool (or coercible to bool), optional
Whether mapping should update existing mapping, i.e.
replace when there is an overlap in keys, add otherwise.
Default value is False.
fix : bool (or coercible to bool), optional
When replacing or modifying an existing mapping, this
determines whether display formats on any data variables
that use this mapping should be expanded to accommodate
the new labels, if necessary.
Default value is False.
Returns
None
Side effects
Stores value -> label map in dataset (does not apply it).
def label_dir(
self)
Display names of defined value -> label maps
Returns
None
Side effects
Displays names of existing value -> label maps.
def label_drop(
self, labnames=None, drop_all=False)
Delete value -> label maps from data set.
Parameters
labnames : str or iterable of str, optional One or more names of existing value -> label maps to display. drop_all : bool (or coercible to bool), optional Whether all value -> label maps should be dropped. Default value is False.
Note
Nothing will be done if neither labnames
nor drop_all
are
specified. If both are specified, `drop_all' will be ignored.
Returns
None
Side effects
Removes value -> label maps from data set. Association between data variables and maps names are not removed.
def label_language(
self, languagename=None, new=False, copy=False, rename=False, delete=False)
Various functionality for manipulating groups of variable and data labels.
Users may, for example, make the same data and variable labels multiple times in different languages, with each language a separate group. This function creates, deletes, renames and swaps groups.
Parameters
languagename : str, optional
Name of label language/group.
Required if using any of the other parameters.
If used without other parameters, the action is to
set specified language/group as "current".
new : bool (or coercible to bool), optional
Used to create new language and set as "current".
New labels are empty when copy
is not specified.
Default value is False.
copy : bool (or coercible to bool), optional
Used to copy the "current" group of labels.
Cannot be used without setting `new'=True.
Hence, also sets the copy as "current".
Default value is False.
rename : bool (or coercible to bool), optional
Rename current group of labels, or set the name of the
current set, if no name has been applied.
Default value is False.
delete : bool (or coercible to bool), optional
Delete given label language/group. Not allowed if there
is only one defined label language/group.
Default value is False.
Note
If no parameters are specified, the action is to list all label
languages/groups. Of new
, copy
, rename
, and delete
, only
new
and copy
may be used together. A languagename
is
restricted to 24 characters and will be truncated if necessary.
Returns
None
Side effects
Creates, deletes, renames, or swaps label languages/groups.
def label_list(
self, labnames=None)
Show value, label pairs for given maps, or for all such maps if none specified.
Parameters
labnames : str or iterable of str, optional One or more names of existing value -> label maps to display. Default is to show all defined maps.
Returns
None
Side effects
Displays value -> label maps.
def label_values(
self, varnames, labname, fix=True)
Associate (possibly non-existent) value -> label map with given data variables.
Parameters
varnames : str or iterable of str
One or more names of data variables.
Abbreviations are allowed if unambiguous.
labname : str
Name of value -> label mapping to use with given variables.
labname
does not need to be the name of an existing map.
fix : bool (or coercible to bool), optional
Whether the variables' display formats should be expanded
to accommodate the labels, if necessary.
Default value is True.
Returns
None
Side effects
Associates (possibly non-existent) value -> label map with given data variables.
def label_variable(
self, varname, label)
Add given label to variable.
Label will be truncated to 80 characters if necessary.
Parameters
varname : str Single varname (abbreviation allowed if unambiguous). label : str Label should be ascii ('iso-8859-1'). Otherwise, the label will not be saved as intended.
Returns
None
Side effects
Adds label to variable.
def list(
self, varnames='', **kwargs)
Print table of data values.
Print table of values for specified variable(s), or all variables if none specified.
Parameters
varnames : str, or iterable of str, optional Default is none specified (i.e. list all). Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous. in_ : iterable, optional Used to specify observations to list. Should be an iterable of int. Default is all observations. if_ : function, optional Used to specify observations to list. Should be a function taking int and returning Boolean (or coercible to Boolean). Default is True for all obs.
Parameters note
If both in_
and if_
are used, the listed observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Displays table of values.
def note_add(
self, evarname, note, replace=False, in_=None)
Add given note for varname or '_dta', or replacing existing note if specified.
Note will be truncated to 67,784 characters if necessary.
Parameters
evarname : str
Name of data variable or 'dta'.
An abbreviation of a variable name is allowed if unambiguous.
note : str
Note should be ascii ('iso-8859-1').
Otherwise, the note will not be saved as intended.
replace : bool (or coercible to bool), optional
Specify that existing note should be replaced.
If replace
is True, in_
must be specified as well.
Otherwise, replace
will be ignored.
Default value is False.
in : int, optional
Note number to replace (>= 1).
Only used if replace
is True.
Returns
None
Side effects
Inserts text as new note or replacement for old note.
def note_drop(
self, evarnames, in_=None)
Drop notes in given numbers for given evarnames.
Parameters
evarnames : str or iterable of str Names of data variable(s) or 'dta'. Abbreviations of variable names are allowed if unambiguous. in : int or iterable of int, optional Note number(s) to drop (>= 1). If `in_' not specified or is None, all notes will be dropped for given evarnames.
Returns
None
Side effects
Deletes notes.
def note_list(
self, evarnames='', in_=None)
List notes in given numbers for given evarnames.
Parameters
evarnames : str or iterable of str Names of data variable(s) or 'dta'. Abbreviations of variable names are allowed if unambiguous. in : int or iterable of int, optional Note number(s) to drop (>= 1). If `in_' not specified or is None, all notes will be dropped for given evarnames.
Returns
None
Side effects
Displays notes.
def note_renumber(
self, evarname)
Remove gaps in note numbers.
Parameters
evarname : str Name of data variable or '_dta'. An abbreviation of a variable name is allowed if unambiguous.
Returns
None
Side effects
Renumbers notes if necessary.
def note_replace(
self, evarname, note, in_)
Replace existing note for varname or '_dta'.
Note will be truncated to 67,784 characters if necessary.
Parameters
evarname : str Name of data variable or 'dta'. An abbreviation of a variable name is allowed if unambiguous. note : str Note should be ascii ('iso-8859-1'). Otherwise, the note will not be saved as intended. in : int Note number to replace (>= 1).
Returns
None
Side effects
Inserts text as replacement for old note.
def note_search(
self, text)
Search in notes for exact matches of given text.
Parameters
text : str
Returns
None
Side effects
Displays notes matching text.
def notes_add(
self, evarname, note, replace=False, in_=None)
Add given note for varname or '_dta', or replacing existing note if specified.
Note will be truncated to 67,784 characters if necessary.
Parameters
evarname : str
Name of data variable or 'dta'.
An abbreviation of a variable name is allowed if unambiguous.
note : str
Note should be ascii ('iso-8859-1').
Otherwise, the note will not be saved as intended.
replace : bool (or coercible to bool), optional
Specify that existing note should be replaced.
If replace
is True, in_
must be specified as well.
Otherwise, replace
will be ignored.
Default value is False.
in : int, optional
Note number to replace (>= 1).
Only used if replace
is True.
Returns
None
Side effects
Inserts text as new note or replacement for old note.
def notes_drop(
self, evarnames, in_=None)
Drop notes in given numbers for given evarnames.
Parameters
evarnames : str or iterable of str Names of data variable(s) or 'dta'. Abbreviations of variable names are allowed if unambiguous. in : int or iterable of int, optional Note number(s) to drop (>= 1). If `in_' not specified or is None, all notes will be dropped for given evarnames.
Returns
None
Side effects
Deletes notes.
def notes_list(
self, evarnames='', in_=None)
List notes in given numbers for given evarnames.
Parameters
evarnames : str or iterable of str Names of data variable(s) or 'dta'. Abbreviations of variable names are allowed if unambiguous. in : int or iterable of int, optional Note number(s) to drop (>= 1). If `in_' not specified or is None, all notes will be dropped for given evarnames.
Returns
None
Side effects
Displays notes.
def notes_renumber(
self, evarname)
Remove gaps in note numbers.
Parameters
evarname : str Name of data variable or '_dta'. An abbreviation of a variable name is allowed if unambiguous.
Returns
None
Side effects
Renumbers notes if necessary.
def notes_replace(
self, evarname, note, in_)
Replace existing note for varname or '_dta'.
Note will be truncated to 67,784 characters if necessary.
Parameters
evarname : str Name of data variable or 'dta'. An abbreviation of a variable name is allowed if unambiguous. note : str Note should be ascii ('iso-8859-1'). Otherwise, the note will not be saved as intended. in : int Note number to replace (>= 1).
Returns
None
Side effects
Inserts text as replacement for old note.
def notes_search(
self, text)
Search in notes for exact matches of given text.
Parameters
text : str
Returns
None
Side effects
Displays notes matching text.
def order(
self, varnames, last=False, before=None, after=None, alpha=False)
Change order of varlist.
Any duplicates in varnames will be ignored.
Parameters
varnames : str, or iterable of str
Can be a str containing one varname (e.g. "mpg"),
a str with multiple varnames (e.g. "make price mpg"),
or an iterable of such str
(e.g. ("make", "price", "mpg") or ("make", "price mpg")).
Abbreviations are allowed if unambiguous.
last : bool (or coercible to bool), optional
Signal that specified variables should come last in the
varlist instead of first. Default is False.
May not be combined with before
or after
.
before : str, optional
Name of variable to put the specified variables before.
An abbreviation is allowed if unambiguous.
By default this option is turned off.
May not be combined with last' or
after'
after : str, optional
Name of variable to put the specified variables after.
An abbreviation is allowed if unambiguous.
By default this option is turned off.
May not be combined with last' or
before'
alpha : bool (or coercible to bool), optional
Signal that varlist should be sorted alphabetically
before rearranging. Default is False.
Returns
None
Side effects
Reorders varlist.
def quiet(
self, q=True)
Allow or disallow output messages.
Parameters
q : bool or coercible to bool Default value is True, meaning disallow messages.
Returns
None
Notes
Methods that are primarily designed for output--like describe
,
list
, and summary
--will show output regardless. Setting this
function affects warnings or other 'unexpected' messages.
def rename(
self, oldname, newname)
Replace old variable name with new.
Parameters
oldname : str Single variable name (abbreviation allowed if unambiguous). newname : str New variable name.
Returns
None
Side effects
Replace old data variable name with new.
def replace(
self, id, values, in_=None, if_=None)
Replace values in given data variable.
Parameters
id : int or str
Single variable index (int) or name (str).
For str, an abbreviation is allowed if unambiguous.
values : iterable
Can be a flat iterable like [1, 5, 9, ...] or iterable of
rows, like [[1], [5], [9], ...].
Should have the same number of values as current number of
observations or as implied by in_
and if_
.
in_ : iterable, optional
Used to specify observations replace.
Should be an iterable of int.
Default is all observations.
if_ : function, optional
Used to specify observations replace.
Should be a function taking int and
returning Boolean (or coercible to Boolean).
Default is True for all obs.
Parameters note
If both in_
and if_
are used, the replaced observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Replaces values in given data variable.
def return_list(
self)
Display any saved results for this dta object.
Returns
None
Side effects
Displays contents of saved results, if any.
def save(
self, address=None, replace=False)
Save current Dta object as dta file.
Parameters
address : str Address of file to save to. Optional if Dta object was created from file or has been saved already, otherwise required. replace : bool, optional Default value is False. True is required to write over existing file.
Returns
None
Side effects
creates or replaces dta file
def set_obs(
self, num_obs)
Increase number of observations in data set.
Parameters
num_obs : int Number of observations to increase to.
Returns
None
Side effects
Changes number of observations. Appends observations with MissingValue instance for numeric variables, "" for string. Marks data as unsorted.
def sort(
self, varnames)
Sort data values according to given variables.
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Sorts observations of the data set.
def summ(
self, varnames='', *args, **kwargs)
Summarize data variables.
Summarize specified variable(s), or, if no variables specified, summarize all variables.
Parameters
varnames : str, or iterable of str, optional
Default is none specified (i.e. summarize all).
Can be a str containing one varname (e.g. "mpg"),
a str with multiple varnames (e.g. "make price mpg"),
or an iterable of such str
(e.g. ("make", "price", "mpg") or ("make", "price mpg")).
Abbreviations are allowed if unambiguous.
detail : bool (or coercible to bool)
May not be combined with meanonly
.
meanonly : bool (or coercible to bool)
May not be combined with detail
.
separator : int
Number of summaries to group together with dividing line.
Has no effect
quietly : bool (or coercible to bool)
Create summary, but do not display. Useful if only wanting
to save summary results, to be displayed with return_list
.
weight : str
Single varname (or abbreviation).
May not be combined with other weights.
aweight : str
Single varname (or abbreviation).
May not be combined with other weights.
fweight : str
Single varname (or abbreviation), of an integer variable.
May not be combined with other weights.
iweight : str
Single varname (or abbreviation).
May not be combined with other weights.
May not be combined with detail
option.
in_ : iterable, optional
Used to specify observations to include in summary.
Should be an iterable of int.
Default is all observations.
if_ : function, optional
Used to specify observations to include in summary.
Should be a function taking int and
returning Boolean (or coercible to Boolean).
Default is True for all obs.
Parameters note
Above parameters can be accessed by name.
Otherwise, the parameters appear in the above order.
If both in_
and if_
are used, the summarized observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Displays summary of specified variable(s). Saves the values
from the last summary, which can be displayed with return_list
.
def summarize(
self, varnames='', *args, **kwargs)
Summarize data variables.
Summarize specified variable(s), or, if no variables specified, summarize all variables.
Parameters
varnames : str, or iterable of str, optional
Default is none specified (i.e. summarize all).
Can be a str containing one varname (e.g. "mpg"),
a str with multiple varnames (e.g. "make price mpg"),
or an iterable of such str
(e.g. ("make", "price", "mpg") or ("make", "price mpg")).
Abbreviations are allowed if unambiguous.
detail : bool (or coercible to bool)
May not be combined with meanonly
.
meanonly : bool (or coercible to bool)
May not be combined with detail
.
separator : int
Number of summaries to group together with dividing line.
Has no effect
quietly : bool (or coercible to bool)
Create summary, but do not display. Useful if only wanting
to save summary results, to be displayed with return_list
.
weight : str
Single varname (or abbreviation).
May not be combined with other weights.
aweight : str
Single varname (or abbreviation).
May not be combined with other weights.
fweight : str
Single varname (or abbreviation), of an integer variable.
May not be combined with other weights.
iweight : str
Single varname (or abbreviation).
May not be combined with other weights.
May not be combined with detail
option.
in_ : iterable, optional
Used to specify observations to include in summary.
Should be an iterable of int.
Default is all observations.
if_ : function, optional
Used to specify observations to include in summary.
Should be a function taking int and
returning Boolean (or coercible to Boolean).
Default is True for all obs.
Parameters note
Above parameters can be accessed by name.
Otherwise, the parameters appear in the above order.
If both in_
and if_
are used, the summarized observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Displays summary of specified variable(s). Saves the values
from the last summary, which can be displayed with return_list
.
def to_list(
self)
Return list of data observations.
Returns
list List of observations, each of which is also a list.
def variable(
self, id)
Get a list of all values of a data variable.
Parameters
id : int or str Single variable index (int) or name (str). For str, an abbreviation is allowed if unambiguous.
Returns
list List of values of the specified data variable.
def xpose(
self, clear=False, varname=False)
Transpose data.
Parameters
clear : Boolean , required The purpose of this parameter is to remind the user that this method replaces the data in the dataset.
Returns
None
Note
This method does not yet support the -promote- option in Stata.
Side effects
Can change almost everything in the data set. Replaces string values with missing. Transposes numeric values in the data, and thus changing number of observations, number of variables, variable names, etc. Removes or replaces existing variable labels, characteristics, display formats, sort info.
class Dta115
A Python class for Stata dataset version 115. It provides methods for creating, opening, manipulating, and saving Stata datasets.
Ancestors (in MRO)
Methods
def __init__(
self, *args, **kwargs)
Initialize Dta object.
Dta objects can be created - from file, - from an iterable of values (as in a list of lists, with one sub-list per observation), - by subscripting an existing Dta (usually done with subscripting syntax like data[::2, (0,4,8)] ), or - by converting one sub-type of Dta to another (for example, converting from version 115 to 117 by converting a Dta115 instance to a Dta117 instance).
New from file
Parameters
address : str Address of dta file, including file name and ".dta".
Example
Dta115("path/to/some_dta_v115.dta") Dta117("path/to/some_dta_v117.dta")
if uncertain of version, open_dta() can open 114, 115, or 117
open_dta("recent_version.dta")
Side effects
If the data set has a label, the label will be printed.
New from iterable
Parameters
varvals : iterable Values to compress : bool (or coercible to bool), optional This sets the default type to attempt to assign to a data variable as byte if compress=True, or float if compress=False. Default type is overridden as necessary. Using compress=True can result in smaller files. Default value is True. single_row : bool (or coercible to bool), optional The code tries to be helpful with inputs. The correct way to specify a single row data set is with a non-string iterable within another iterable, as in ((0,1,2,3)) or [[0,1,2,3]]. With single_row=True, a single row can be specified as, for example, just (0,1,2,3) or [0,1,2,3]. (Don't combine ((0,1,2,3)) with single_row=True.) Default value is False.
Example
v = [[0.0, 0.1, 0.2],[1.0, 1.1, 1.2],[2.0,2.1,2.2]] Dta117(v)
Subscripting a Dta instance (usually used indirectly)
Parameters
old_dta : Dta instance
sel_rows : iterable of int, optional
The rows (observations) to be selected from the old_dta
.
Defaults to all observations.
sel_cols : iterable of int, optional
The cols (data variables) to be selected from the old_dta
.
Defaults to all variables.
Example
take even-numbered observations and variables 0, 4, 8
smaller_dta = some_dta[::2, (0,4,8)]
Converting a Dta instance
Parameters
old_dta : Dta instance
sel_rows : iterable of int, optional
The rows (observations) to be selected from the old_dta
.
Defaults to all observations.
sel_cols : iterable of int, optional
The cols (data variables) to be selected from the old_dta
.
Defaults to all variables.
Example
open a version 115 file
dta115 = open_dta("some_dta_v115.dta")
convert to version 117
dta117 = Dta117(dta115)
Side effects
Data may be changed or variables dropped if converting from a more permissive format to a more restrictive one.
Returns
All examples above return an instance of a Dta sub-class.
Side effects
Initializes Dta object.
def append_obs(
self, value)
Inheritance:
Dta
.append_obs
Append observations to the end of the dataset.
Parameters
value : iterable Should be an iterable of iterables, one sub-iterable per observation. The observations should contain as many values as there are variables in the data set, and the values should have correct type.
Returns
None
Side effects
Creates new observations in the data set, and inputs the given values into those observations.
def append_var(
self, name, values, st_type=None, compress=True)
Inheritance:
Dta
.append_var
Add new variable to data set.
Parameters
name : str Name of variable to be created. values : iterable Should be a flat iterable like [1, 5, 9, ...] or (1, 5, 9, ...). Not like [[1], [5], [9], ...]. st_type : int or str, optional Examples: 212 or "str212", 254 or "float". Intended Stata type of the data variable. The intended type will be overridden when necessary. Default value depends on the given values. compress : bool (or coercible to bool), optional If st_type is None, this sets st_type to byte if compress=True, or float if compress=False. Using compress=True can result in smaller files. Default value is True.
Returns
None
Side effects
Adds new variable to data set.
def check(
self, version=None)
Determine whether saved data set would conform to limits of given Stata version. (Not .dta version.)
See -help limits- in Stata for more info.
Parameters
version : int, optional Specify a Stata version to check against. Default is to check against Stata version 13.
Returns
None
Side effects
Display summary of limits violations, if any.
def clonevar(
self, oldname, newname)
Create a data variable into a new variable.
New data variable will have the same data values, display format, labels, value labels, notes, and characteristics.
Parameters
oldname : str Single variable name (abbreviation allowed if unambiguous). newname : str New variable name.
Returns
None
Side effects
Creates new variable. Copies data values, display format, labels, value labels, notes, and characteristics.
def copy(
self)
Create a copy of the current Dta instance.
Returns
Dta instance
def describe(
self, simple=False, short=False, fullnames=False, numbers=False, varlist=False)
Display a description of the data set.
Paramters
simple : bool (or coercible to bool), optional
Specify that only a list of variable names be displayed.
No other options may be combined with simple
.
Default value is False.
short : bool (or coercible to bool), optional
Specify that only data set information be displayed.
No information about individual variables will be displayed.
Default value is False.
fullnames : bool (or coercible to bool), optional
Specify that full variable names be used.
Default value is False.
numbers : bool (or coercible to bool), optional
Specify that variables' numbers be included.
Default value is False.
varlist : bool (or coercible to bool), optional
Specify that sortlist and varlist information be saved
(accessible via the return_list
method).
Default value is False.
Returns
None
Side effects
Displays description of data set. Saves associated values,
which can be displayed with return_list
method.
def drop_obs(
self, in_=None, if_=None, all_obs=False)
Drop observations from the data set.
Parameters
in_ : iterable, optional Used to specify observations to drop. Should be an iterable of int. Default is all observations. if_ : function, optional Used to specify observations to drop. Should be a function taking int and returning Boolean (or coercible to Boolean). Default is True for all obs. all_obs : bool or coercible to Boolean, optional Option to drop all observations. Default value is False.
Parameters note
If both in_
and if_
are used, the dropped observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Deletes specified observations.
def drop_var(
self, varnames)
Delete specified variable(s).
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Deletes specified data variables.
def drop_vars(
self, varnames)
Delete specified variable(s).
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Deletes specified data variables.
def format(
self, varnames, fmts)
Set the Stata display format of given data variables.
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous. fmts : str, or iterable of str Can be a str containing one format (e.g. "%9.2f"), a str with multiple formats (e.g. "%9.2f %12s %9.0g"), or an iterable of such str (e.g. ("%9.2f", "%12s", "%9.0g") or ("%9.2f", "%12s %9.0g")).
Notes
If there are fewer formats than varnames, the last format will be repeated. Any extraneous formats will be ignored.
Returns
None
Side effects
Sets the display format of the given data variables.
def get(
self, row, col)
Get single data value.
Parameters
row : integer Row (observation) number of data value. col : integer Column (data variable) number of data value.
Returns
string, numeric, missing value, or binary data value
def index(
self, varname)
Get index of given data variable.
Parameters
varname : str Single varname (abbreviation allowed if unambiguous).
Returns
int Index of variable in data set.
def ismissing(
self, item)
Determine if item qualifies as a numeric missing value.
Parameters
item : None, int, float, or MissingValue instance
Returns
bool
Notes
This function is not meant to be used with non-numeric or non-real values, and will raise an error when given such.
def keep_obs(
self, in_=None, if_=None)
Keep specified observations, remove all others.
Parameters
in_ : iterable, optional Used to specify observations to keep. Should be an iterable of int. Default is all observations. if_ : function, optional Used to specify observations to keep. Should be a function taking int and returning Boolean (or coercible to Boolean). Default is True for all obs.
Parameters note
If both in_
and if_
are used, the kept observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Deletes all observations except those specified.
def keep_var(
self, varnames)
Keep specified variable(s), delete all others.
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Deletes data variables other than those specified.
def keep_vars(
self, varnames)
Keep specified variable(s), delete all others.
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Deletes data variables other than those specified.
def label_copy(
self, orig_name, copy_name, replace=False)
Inheritance:
Dta
.label_copy
Make a copy of mapping orig_name
with name copy_name
Parameters
orig_name : str
Name of the existing value label mapping.
copy_name : str
Name to be given to the copy.
replace : bool (or coercible to bool), optional
Whether the copy should replace an existing mapping.
Required if a mapping with name copy_name
already exists.
Default value is False.
Returns
None
Side effects
Stores or replaces a copy of a value -> label map in the data set.
def label_data(
self, label)
Inheritance:
Dta
.label_data
Add given label to data.
Label will be truncated to 80 characters if necessary.
Parameters
label : str Label should be ascii ('iso-8859-1'). Otherwise, the label will not be saved as intended.
Returns
None
Side effects
Adds label to data.
def label_define(
self, name, mapping, add=False, replace=False, modify=False, fix=True)
Inheritance:
Dta
.label_define
Define a VALUE label, a mapping from numeric values to string.
Parameters
name : str
Name of the value label, i.e. name of the mapping.
If a mapping with this name already exists, add
,
replace
, or modify
should be set to True.
mapping : dict
Keys should be int or float, dict values should be str.
add : bool (or coercible to bool), optional
Whether mapping should be added to existing mapping.
An error will be raised if old and new mapping share keys.
Default value is False.
replace : bool (or coercible to bool), optional
Whether mapping should replace existing mapping entirely.
Default value is False.
modify : bool (or coercible to bool), optional
Whether mapping should update existing mapping, i.e.
replace when there is an overlap in keys, add otherwise.
Default value is False.
fix : bool (or coercible to bool), optional
When replacing or modifying an existing mapping, this
determines whether display formats on any data variables
that use this mapping should be expanded to accommodate
the new labels, if necessary.
Default value is False.
Returns
None
Side effects
Stores value -> label map in dataset (does not apply it).
def label_dir(
self)
Display names of defined value -> label maps
Returns
None
Side effects
Displays names of existing value -> label maps.
def label_drop(
self, labnames=None, drop_all=False)
Inheritance:
Dta
.label_drop
Delete value -> label maps from data set.
Parameters
labnames : str or iterable of str, optional One or more names of existing value -> label maps to display. drop_all : bool (or coercible to bool), optional Whether all value -> label maps should be dropped. Default value is False.
Note
Nothing will be done if neither labnames
nor drop_all
are
specified. If both are specified, `drop_all' will be ignored.
Returns
None
Side effects
Removes value -> label maps from data set. Association between data variables and maps names are not removed.
def label_language(
self, languagename=None, new=False, copy=False, rename=False, delete=False)
Inheritance:
Dta
.label_language
Various functionality for manipulating groups of variable and data labels.
Users may, for example, make the same data and variable labels multiple times in different languages, with each language a separate group. This function creates, deletes, renames and swaps groups.
Parameters
languagename : str, optional
Name of label language/group.
Required if using any of the other parameters.
If used without other parameters, the action is to
set specified language/group as "current".
new : bool (or coercible to bool), optional
Used to create new language and set as "current".
New labels are empty when copy
is not specified.
Default value is False.
copy : bool (or coercible to bool), optional
Used to copy the "current" group of labels.
Cannot be used without setting `new'=True.
Hence, also sets the copy as "current".
Default value is False.
rename : bool (or coercible to bool), optional
Rename current group of labels, or set the name of the
current set, if no name has been applied.
Default value is False.
delete : bool (or coercible to bool), optional
Delete given label language/group. Not allowed if there
is only one defined label language/group.
Default value is False.
Note
If no parameters are specified, the action is to list all label
languages/groups. Of new
, copy
, rename
, and delete
, only
new
and copy
may be used together. A languagename
is
restricted to 24 characters and will be truncated if necessary.
Returns
None
Side effects
Creates, deletes, renames, or swaps label languages/groups.
def label_list(
self, labnames=None)
Inheritance:
Dta
.label_list
Show value, label pairs for given maps, or for all such maps if none specified.
Parameters
labnames : str or iterable of str, optional One or more names of existing value -> label maps to display. Default is to show all defined maps.
Returns
None
Side effects
Displays value -> label maps.
def label_values(
self, varnames, labname, fix=True)
Inheritance:
Dta
.label_values
Associate (possibly non-existent) value -> label map with given data variables.
Parameters
varnames : str or iterable of str
One or more names of data variables.
Abbreviations are allowed if unambiguous.
labname : str
Name of value -> label mapping to use with given variables.
labname
does not need to be the name of an existing map.
fix : bool (or coercible to bool), optional
Whether the variables' display formats should be expanded
to accommodate the labels, if necessary.
Default value is True.
Returns
None
Side effects
Associates (possibly non-existent) value -> label map with given data variables.
def label_variable(
self, varname, label)
Inheritance:
Dta
.label_variable
Add given label to variable.
Label will be truncated to 80 characters if necessary.
Parameters
varname : str Single varname (abbreviation allowed if unambiguous). label : str Label should be ascii ('iso-8859-1'). Otherwise, the label will not be saved as intended.
Returns
None
Side effects
Adds label to variable.
def list(
self, varnames='', **kwargs)
Print table of data values.
Print table of values for specified variable(s), or all variables if none specified.
Parameters
varnames : str, or iterable of str, optional Default is none specified (i.e. list all). Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous. in_ : iterable, optional Used to specify observations to list. Should be an iterable of int. Default is all observations. if_ : function, optional Used to specify observations to list. Should be a function taking int and returning Boolean (or coercible to Boolean). Default is True for all obs.
Parameters note
If both in_
and if_
are used, the listed observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Displays table of values.
def note_add(
self, evarname, note, replace=False, in_=None)
Add given note for varname or '_dta', or replacing existing note if specified.
Note will be truncated to 67,784 characters if necessary.
Parameters
evarname : str
Name of data variable or 'dta'.
An abbreviation of a variable name is allowed if unambiguous.
note : str
Note should be ascii ('iso-8859-1').
Otherwise, the note will not be saved as intended.
replace : bool (or coercible to bool), optional
Specify that existing note should be replaced.
If replace
is True, in_
must be specified as well.
Otherwise, replace
will be ignored.
Default value is False.
in : int, optional
Note number to replace (>= 1).
Only used if replace
is True.
Returns
None
Side effects
Inserts text as new note or replacement for old note.
def note_drop(
self, evarnames, in_=None)
Drop notes in given numbers for given evarnames.
Parameters
evarnames : str or iterable of str Names of data variable(s) or 'dta'. Abbreviations of variable names are allowed if unambiguous. in : int or iterable of int, optional Note number(s) to drop (>= 1). If `in_' not specified or is None, all notes will be dropped for given evarnames.
Returns
None
Side effects
Deletes notes.
def note_list(
self, evarnames='', in_=None)
List notes in given numbers for given evarnames.
Parameters
evarnames : str or iterable of str Names of data variable(s) or 'dta'. Abbreviations of variable names are allowed if unambiguous. in : int or iterable of int, optional Note number(s) to drop (>= 1). If `in_' not specified or is None, all notes will be dropped for given evarnames.
Returns
None
Side effects
Displays notes.
def note_renumber(
self, evarname)
Inheritance:
Dta
.note_renumber
Remove gaps in note numbers.
Parameters
evarname : str Name of data variable or '_dta'. An abbreviation of a variable name is allowed if unambiguous.
Returns
None
Side effects
Renumbers notes if necessary.
def note_replace(
self, evarname, note, in_)
Inheritance:
Dta
.note_replace
Replace existing note for varname or '_dta'.
Note will be truncated to 67,784 characters if necessary.
Parameters
evarname : str Name of data variable or 'dta'. An abbreviation of a variable name is allowed if unambiguous. note : str Note should be ascii ('iso-8859-1'). Otherwise, the note will not be saved as intended. in : int Note number to replace (>= 1).
Returns
None
Side effects
Inserts text as replacement for old note.
def note_search(
self, text)
Inheritance:
Dta
.note_search
Search in notes for exact matches of given text.
Parameters
text : str
Returns
None
Side effects
Displays notes matching text.
def notes_add(
self, evarname, note, replace=False, in_=None)
Add given note for varname or '_dta', or replacing existing note if specified.
Note will be truncated to 67,784 characters if necessary.
Parameters
evarname : str
Name of data variable or 'dta'.
An abbreviation of a variable name is allowed if unambiguous.
note : str
Note should be ascii ('iso-8859-1').
Otherwise, the note will not be saved as intended.
replace : bool (or coercible to bool), optional
Specify that existing note should be replaced.
If replace
is True, in_
must be specified as well.
Otherwise, replace
will be ignored.
Default value is False.
in : int, optional
Note number to replace (>= 1).
Only used if replace
is True.
Returns
None
Side effects
Inserts text as new note or replacement for old note.
def notes_drop(
self, evarnames, in_=None)
Inheritance:
Dta
.notes_drop
Drop notes in given numbers for given evarnames.
Parameters
evarnames : str or iterable of str Names of data variable(s) or 'dta'. Abbreviations of variable names are allowed if unambiguous. in : int or iterable of int, optional Note number(s) to drop (>= 1). If `in_' not specified or is None, all notes will be dropped for given evarnames.
Returns
None
Side effects
Deletes notes.
def notes_list(
self, evarnames='', in_=None)
Inheritance:
Dta
.notes_list
List notes in given numbers for given evarnames.
Parameters
evarnames : str or iterable of str Names of data variable(s) or 'dta'. Abbreviations of variable names are allowed if unambiguous. in : int or iterable of int, optional Note number(s) to drop (>= 1). If `in_' not specified or is None, all notes will be dropped for given evarnames.
Returns
None
Side effects
Displays notes.
def notes_renumber(
self, evarname)
Inheritance:
Dta
.notes_renumber
Remove gaps in note numbers.
Parameters
evarname : str Name of data variable or '_dta'. An abbreviation of a variable name is allowed if unambiguous.
Returns
None
Side effects
Renumbers notes if necessary.
def notes_replace(
self, evarname, note, in_)
Inheritance:
Dta
.notes_replace
Replace existing note for varname or '_dta'.
Note will be truncated to 67,784 characters if necessary.
Parameters
evarname : str Name of data variable or 'dta'. An abbreviation of a variable name is allowed if unambiguous. note : str Note should be ascii ('iso-8859-1'). Otherwise, the note will not be saved as intended. in : int Note number to replace (>= 1).
Returns
None
Side effects
Inserts text as replacement for old note.
def notes_search(
self, text)
Inheritance:
Dta
.notes_search
Search in notes for exact matches of given text.
Parameters
text : str
Returns
None
Side effects
Displays notes matching text.
def order(
self, varnames, last=False, before=None, after=None, alpha=False)
Change order of varlist.
Any duplicates in varnames will be ignored.
Parameters
varnames : str, or iterable of str
Can be a str containing one varname (e.g. "mpg"),
a str with multiple varnames (e.g. "make price mpg"),
or an iterable of such str
(e.g. ("make", "price", "mpg") or ("make", "price mpg")).
Abbreviations are allowed if unambiguous.
last : bool (or coercible to bool), optional
Signal that specified variables should come last in the
varlist instead of first. Default is False.
May not be combined with before
or after
.
before : str, optional
Name of variable to put the specified variables before.
An abbreviation is allowed if unambiguous.
By default this option is turned off.
May not be combined with last' or
after'
after : str, optional
Name of variable to put the specified variables after.
An abbreviation is allowed if unambiguous.
By default this option is turned off.
May not be combined with last' or
before'
alpha : bool (or coercible to bool), optional
Signal that varlist should be sorted alphabetically
before rearranging. Default is False.
Returns
None
Side effects
Reorders varlist.
def quiet(
self, q=True)
Allow or disallow output messages.
Parameters
q : bool or coercible to bool Default value is True, meaning disallow messages.
Returns
None
Notes
Methods that are primarily designed for output--like describe
,
list
, and summary
--will show output regardless. Setting this
function affects warnings or other 'unexpected' messages.
def rename(
self, oldname, newname)
Replace old variable name with new.
Parameters
oldname : str Single variable name (abbreviation allowed if unambiguous). newname : str New variable name.
Returns
None
Side effects
Replace old data variable name with new.
def replace(
self, id, values, in_=None, if_=None)
Replace values in given data variable.
Parameters
id : int or str
Single variable index (int) or name (str).
For str, an abbreviation is allowed if unambiguous.
values : iterable
Can be a flat iterable like [1, 5, 9, ...] or iterable of
rows, like [[1], [5], [9], ...].
Should have the same number of values as current number of
observations or as implied by in_
and if_
.
in_ : iterable, optional
Used to specify observations replace.
Should be an iterable of int.
Default is all observations.
if_ : function, optional
Used to specify observations replace.
Should be a function taking int and
returning Boolean (or coercible to Boolean).
Default is True for all obs.
Parameters note
If both in_
and if_
are used, the replaced observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Replaces values in given data variable.
def return_list(
self)
Inheritance:
Dta
.return_list
Display any saved results for this dta object.
Returns
None
Side effects
Displays contents of saved results, if any.
def save(
self, address=None, replace=False)
Save current Dta object as dta file.
Parameters
address : str Address of file to save to. Optional if Dta object was created from file or has been saved already, otherwise required. replace : bool, optional Default value is False. True is required to write over existing file.
Returns
None
Side effects
creates or replaces dta file
def set_obs(
self, num_obs)
Increase number of observations in data set.
Parameters
num_obs : int Number of observations to increase to.
Returns
None
Side effects
Changes number of observations. Appends observations with MissingValue instance for numeric variables, "" for string. Marks data as unsorted.
def sort(
self, varnames)
Sort data values according to given variables.
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Sorts observations of the data set.
def summ(
self, varnames='', *args, **kwargs)
Summarize data variables.
Summarize specified variable(s), or, if no variables specified, summarize all variables.
Parameters
varnames : str, or iterable of str, optional
Default is none specified (i.e. summarize all).
Can be a str containing one varname (e.g. "mpg"),
a str with multiple varnames (e.g. "make price mpg"),
or an iterable of such str
(e.g. ("make", "price", "mpg") or ("make", "price mpg")).
Abbreviations are allowed if unambiguous.
detail : bool (or coercible to bool)
May not be combined with meanonly
.
meanonly : bool (or coercible to bool)
May not be combined with detail
.
separator : int
Number of summaries to group together with dividing line.
Has no effect
quietly : bool (or coercible to bool)
Create summary, but do not display. Useful if only wanting
to save summary results, to be displayed with return_list
.
weight : str
Single varname (or abbreviation).
May not be combined with other weights.
aweight : str
Single varname (or abbreviation).
May not be combined with other weights.
fweight : str
Single varname (or abbreviation), of an integer variable.
May not be combined with other weights.
iweight : str
Single varname (or abbreviation).
May not be combined with other weights.
May not be combined with detail
option.
in_ : iterable, optional
Used to specify observations to include in summary.
Should be an iterable of int.
Default is all observations.
if_ : function, optional
Used to specify observations to include in summary.
Should be a function taking int and
returning Boolean (or coercible to Boolean).
Default is True for all obs.
Parameters note
Above parameters can be accessed by name.
Otherwise, the parameters appear in the above order.
If both in_
and if_
are used, the summarized observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Displays summary of specified variable(s). Saves the values
from the last summary, which can be displayed with return_list
.
def summarize(
self, varnames='', *args, **kwargs)
Summarize data variables.
Summarize specified variable(s), or, if no variables specified, summarize all variables.
Parameters
varnames : str, or iterable of str, optional
Default is none specified (i.e. summarize all).
Can be a str containing one varname (e.g. "mpg"),
a str with multiple varnames (e.g. "make price mpg"),
or an iterable of such str
(e.g. ("make", "price", "mpg") or ("make", "price mpg")).
Abbreviations are allowed if unambiguous.
detail : bool (or coercible to bool)
May not be combined with meanonly
.
meanonly : bool (or coercible to bool)
May not be combined with detail
.
separator : int
Number of summaries to group together with dividing line.
Has no effect
quietly : bool (or coercible to bool)
Create summary, but do not display. Useful if only wanting
to save summary results, to be displayed with return_list
.
weight : str
Single varname (or abbreviation).
May not be combined with other weights.
aweight : str
Single varname (or abbreviation).
May not be combined with other weights.
fweight : str
Single varname (or abbreviation), of an integer variable.
May not be combined with other weights.
iweight : str
Single varname (or abbreviation).
May not be combined with other weights.
May not be combined with detail
option.
in_ : iterable, optional
Used to specify observations to include in summary.
Should be an iterable of int.
Default is all observations.
if_ : function, optional
Used to specify observations to include in summary.
Should be a function taking int and
returning Boolean (or coercible to Boolean).
Default is True for all obs.
Parameters note
Above parameters can be accessed by name.
Otherwise, the parameters appear in the above order.
If both in_
and if_
are used, the summarized observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Displays summary of specified variable(s). Saves the values
from the last summary, which can be displayed with return_list
.
def to_list(
self)
Return list of data observations.
Returns
list List of observations, each of which is also a list.
def variable(
self, id)
Get a list of all values of a data variable.
Parameters
id : int or str Single variable index (int) or name (str). For str, an abbreviation is allowed if unambiguous.
Returns
list List of values of the specified data variable.
def xpose(
self, clear=False, varname=False)
Transpose data.
Parameters
clear : Boolean , required The purpose of this parameter is to remind the user that this method replaces the data in the dataset.
Returns
None
Note
This method does not yet support the -promote- option in Stata.
Side effects
Can change almost everything in the data set. Replaces string values with missing. Transposes numeric values in the data, and thus changing number of observations, number of variables, variable names, etc. Removes or replaces existing variable labels, characteristics, display formats, sort info.
class Dta117
A Python class for Stata dataset version 117. It provides methods for creating, opening, manipulating, and saving Stata datasets.
Ancestors (in MRO)
Methods
def __init__(
self, *args, **kwargs)
Initialize Dta object.
Dta objects can be created - from file, - from an iterable of values (as in a list of lists, with one sub-list per observation), - by subscripting an existing Dta (usually done with subscripting syntax like data[::2, (0,4,8)] ), or - by converting one sub-type of Dta to another (for example, converting from version 115 to 117 by converting a Dta115 instance to a Dta117 instance).
New from file
Parameters
address : str Address of dta file, including file name and ".dta".
Example
Dta115("path/to/some_dta_v115.dta") Dta117("path/to/some_dta_v117.dta")
if uncertain of version, open_dta() can open 114, 115, or 117
open_dta("recent_version.dta")
Side effects
If the data set has a label, the label will be printed.
New from iterable
Parameters
varvals : iterable Values to compress : bool (or coercible to bool), optional This sets the default type to attempt to assign to a data variable as byte if compress=True, or float if compress=False. Default type is overridden as necessary. Using compress=True can result in smaller files. Default value is True. single_row : bool (or coercible to bool), optional The code tries to be helpful with inputs. The correct way to specify a single row data set is with a non-string iterable within another iterable, as in ((0,1,2,3)) or [[0,1,2,3]]. With single_row=True, a single row can be specified as, for example, just (0,1,2,3) or [0,1,2,3]. (Don't combine ((0,1,2,3)) with single_row=True.) Default value is False.
Example
v = [[0.0, 0.1, 0.2],[1.0, 1.1, 1.2],[2.0,2.1,2.2]] Dta117(v)
Subscripting a Dta instance (usually used indirectly)
Parameters
old_dta : Dta instance
sel_rows : iterable of int, optional
The rows (observations) to be selected from the old_dta
.
Defaults to all observations.
sel_cols : iterable of int, optional
The cols (data variables) to be selected from the old_dta
.
Defaults to all variables.
Example
take even-numbered observations and variables 0, 4, 8
smaller_dta = some_dta[::2, (0,4,8)]
Converting a Dta instance
Parameters
old_dta : Dta instance
sel_rows : iterable of int, optional
The rows (observations) to be selected from the old_dta
.
Defaults to all observations.
sel_cols : iterable of int, optional
The cols (data variables) to be selected from the old_dta
.
Defaults to all variables.
Example
open a version 115 file
dta115 = open_dta("some_dta_v115.dta")
convert to version 117
dta117 = Dta117(dta115)
Side effects
Data may be changed or variables dropped if converting from a more permissive format to a more restrictive one.
Returns
All examples above return an instance of a Dta sub-class.
Side effects
Initializes Dta object.
def append_obs(
self, value)
Inheritance:
Dta
.append_obs
Append observations to the end of the dataset.
Parameters
value : iterable Should be an iterable of iterables, one sub-iterable per observation. The observations should contain as many values as there are variables in the data set, and the values should have correct type.
Returns
None
Side effects
Creates new observations in the data set, and inputs the given values into those observations.
def append_var(
self, name, values, st_type=None, compress=True)
Inheritance:
Dta
.append_var
Add new variable to data set.
Parameters
name : str Name of variable to be created. values : iterable Should be a flat iterable like [1, 5, 9, ...] or (1, 5, 9, ...). Not like [[1], [5], [9], ...]. st_type : int or str, optional Examples: 212 or "str212", 65527 or "float". Intended Stata type of the data variable. The intended type will be overridden when necessary. Default value depends on the given values. compress : bool (or coercible to bool), optional If st_type is None, this sets st_type to byte if compress=True, or float if compress=False. Using compress=True can result in smaller files. Default value is True.
Returns
None
Side effects
Adds new variable to data set.
def check(
self, version=None)
Determine whether saved data set would conform to limits of given Stata version. (Not .dta version.)
See -help limits- in Stata for more info.
Parameters
version : int, optional Specify a Stata version to check against. Default is to check against Stata version 13.
Returns
None
Side effects
Display summary of limits violations, if any.
def clonevar(
self, oldname, newname)
Create a data variable into a new variable.
New data variable will have the same data values, display format, labels, value labels, notes, and characteristics.
Parameters
oldname : str Single variable name (abbreviation allowed if unambiguous). newname : str New variable name.
Returns
None
Side effects
Creates new variable. Copies data values, display format, labels, value labels, notes, and characteristics.
def copy(
self)
Create a copy of the current Dta instance.
Returns
Dta instance
def describe(
self, simple=False, short=False, fullnames=False, numbers=False, varlist=False)
Display a description of the data set.
Paramters
simple : bool (or coercible to bool), optional
Specify that only a list of variable names be displayed.
No other options may be combined with simple
.
Default value is False.
short : bool (or coercible to bool), optional
Specify that only data set information be displayed.
No information about individual variables will be displayed.
Default value is False.
fullnames : bool (or coercible to bool), optional
Specify that full variable names be used.
Default value is False.
numbers : bool (or coercible to bool), optional
Specify that variables' numbers be included.
Default value is False.
varlist : bool (or coercible to bool), optional
Specify that sortlist and varlist information be saved
(accessible via the return_list
method).
Default value is False.
Returns
None
Side effects
Displays description of data set. Saves associated values,
which can be displayed with return_list
method.
def drop_obs(
self, in_=None, if_=None, all_obs=False)
Drop observations from the data set.
Parameters
in_ : iterable, optional Used to specify observations to drop. Should be an iterable of int. Default is all observations. if_ : function, optional Used to specify observations to drop. Should be a function taking int and returning Boolean (or coercible to Boolean). Default is True for all obs. all_obs : bool or coercible to Boolean, optional Option to drop all observations. Default value is False.
Parameters note
If both in_
and if_
are used, the dropped observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Deletes specified observations.
def drop_var(
self, varnames)
Delete specified variable(s).
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Deletes specified data variables.
def drop_vars(
self, varnames)
Delete specified variable(s).
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Deletes specified data variables.
def format(
self, varnames, fmts)
Set the Stata display format of given data variables.
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous. fmts : str, or iterable of str Can be a str containing one format (e.g. "%9.2f"), a str with multiple formats (e.g. "%9.2f %12s %9.0g"), or an iterable of such str (e.g. ("%9.2f", "%12s", "%9.0g") or ("%9.2f", "%12s %9.0g")).
Notes
If there are fewer formats than varnames, the last format will be repeated. Any extraneous formats will be ignored.
Returns
None
Side effects
Sets the display format of the given data variables.
def get(
self, row, col)
Get single data value.
Parameters
row : integer Row (observation) number of data value. col : integer Column (data variable) number of data value.
Returns
string, numeric, missing value, or binary data value
def index(
self, varname)
Get index of given data variable.
Parameters
varname : str Single varname (abbreviation allowed if unambiguous).
Returns
int Index of variable in data set.
def ismissing(
self, item)
Determine if item qualifies as a numeric missing value.
Parameters
item : None, int, float, or MissingValue instance
Returns
bool
Notes
This function is not meant to be used with non-numeric or non-real values, and will raise an error when given such.
def keep_obs(
self, in_=None, if_=None)
Keep specified observations, remove all others.
Parameters
in_ : iterable, optional Used to specify observations to keep. Should be an iterable of int. Default is all observations. if_ : function, optional Used to specify observations to keep. Should be a function taking int and returning Boolean (or coercible to Boolean). Default is True for all obs.
Parameters note
If both in_
and if_
are used, the kept observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Deletes all observations except those specified.
def keep_var(
self, varnames)
Keep specified variable(s), delete all others.
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Deletes data variables other than those specified.
def keep_vars(
self, varnames)
Keep specified variable(s), delete all others.
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Deletes data variables other than those specified.
def label_copy(
self, orig_name, copy_name, replace=False)
Inheritance:
Dta
.label_copy
Make a copy of mapping orig_name
with name copy_name
Parameters
orig_name : str
Name of the existing value label mapping.
copy_name : str
Name to be given to the copy.
replace : bool (or coercible to bool), optional
Whether the copy should replace an existing mapping.
Required if a mapping with name copy_name
already exists.
Default value is False.
Returns
None
Side effects
Stores or replaces a copy of a value -> label map in the data set.
def label_data(
self, label)
Inheritance:
Dta
.label_data
Add given label to data.
Label will be truncated to 80 characters if necessary.
Parameters
label : str Label should be ascii ('iso-8859-1'). Otherwise, the label will not be saved as intended.
Returns
None
Side effects
Adds label to data.
def label_define(
self, name, mapping, add=False, replace=False, modify=False, fix=True)
Inheritance:
Dta
.label_define
Define a VALUE label, a mapping from numeric values to string.
Parameters
name : str
Name of the value label, i.e. name of the mapping.
If a mapping with this name already exists, add
,
replace
, or modify
should be set to True.
mapping : dict
Keys should be int or float, dict values should be str.
add : bool (or coercible to bool), optional
Whether mapping should be added to existing mapping.
An error will be raised if old and new mapping share keys.
Default value is False.
replace : bool (or coercible to bool), optional
Whether mapping should replace existing mapping entirely.
Default value is False.
modify : bool (or coercible to bool), optional
Whether mapping should update existing mapping, i.e.
replace when there is an overlap in keys, add otherwise.
Default value is False.
fix : bool (or coercible to bool), optional
When replacing or modifying an existing mapping, this
determines whether display formats on any data variables
that use this mapping should be expanded to accommodate
the new labels, if necessary.
Default value is False.
Returns
None
Side effects
Stores value -> label map in dataset (does not apply it).
def label_dir(
self)
Display names of defined value -> label maps
Returns
None
Side effects
Displays names of existing value -> label maps.
def label_drop(
self, labnames=None, drop_all=False)
Inheritance:
Dta
.label_drop
Delete value -> label maps from data set.
Parameters
labnames : str or iterable of str, optional One or more names of existing value -> label maps to display. drop_all : bool (or coercible to bool), optional Whether all value -> label maps should be dropped. Default value is False.
Note
Nothing will be done if neither labnames
nor drop_all
are
specified. If both are specified, `drop_all' will be ignored.
Returns
None
Side effects
Removes value -> label maps from data set. Association between data variables and maps names are not removed.
def label_language(
self, languagename=None, new=False, copy=False, rename=False, delete=False)
Inheritance:
Dta
.label_language
Various functionality for manipulating groups of variable and data labels.
Users may, for example, make the same data and variable labels multiple times in different languages, with each language a separate group. This function creates, deletes, renames and swaps groups.
Parameters
languagename : str, optional
Name of label language/group.
Required if using any of the other parameters.
If used without other parameters, the action is to
set specified language/group as "current".
new : bool (or coercible to bool), optional
Used to create new language and set as "current".
New labels are empty when copy
is not specified.
Default value is False.
copy : bool (or coercible to bool), optional
Used to copy the "current" group of labels.
Cannot be used without setting `new'=True.
Hence, also sets the copy as "current".
Default value is False.
rename : bool (or coercible to bool), optional
Rename current group of labels, or set the name of the
current set, if no name has been applied.
Default value is False.
delete : bool (or coercible to bool), optional
Delete given label language/group. Not allowed if there
is only one defined label language/group.
Default value is False.
Note
If no parameters are specified, the action is to list all label
languages/groups. Of new
, copy
, rename
, and delete
, only
new
and copy
may be used together. A languagename
is
restricted to 24 characters and will be truncated if necessary.
Returns
None
Side effects
Creates, deletes, renames, or swaps label languages/groups.
def label_list(
self, labnames=None)
Inheritance:
Dta
.label_list
Show value, label pairs for given maps, or for all such maps if none specified.
Parameters
labnames : str or iterable of str, optional One or more names of existing value -> label maps to display. Default is to show all defined maps.
Returns
None
Side effects
Displays value -> label maps.
def label_values(
self, varnames, labname, fix=True)
Inheritance:
Dta
.label_values
Associate (possibly non-existent) value -> label map with given data variables.
Parameters
varnames : str or iterable of str
One or more names of data variables.
Abbreviations are allowed if unambiguous.
labname : str
Name of value -> label mapping to use with given variables.
labname
does not need to be the name of an existing map.
fix : bool (or coercible to bool), optional
Whether the variables' display formats should be expanded
to accommodate the labels, if necessary.
Default value is True.
Returns
None
Side effects
Associates (possibly non-existent) value -> label map with given data variables.
def label_variable(
self, varname, label)
Inheritance:
Dta
.label_variable
Add given label to variable.
Label will be truncated to 80 characters if necessary.
Parameters
varname : str Single varname (abbreviation allowed if unambiguous). label : str Label should be ascii ('iso-8859-1'). Otherwise, the label will not be saved as intended.
Returns
None
Side effects
Adds label to variable.
def list(
self, varnames='', **kwargs)
Print table of data values.
Print table of values for specified variable(s), or all variables if none specified.
Parameters
varnames : str, or iterable of str, optional Default is none specified (i.e. list all). Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous. in_ : iterable, optional Used to specify observations to list. Should be an iterable of int. Default is all observations. if_ : function, optional Used to specify observations to list. Should be a function taking int and returning Boolean (or coercible to Boolean). Default is True for all obs.
Parameters note
If both in_
and if_
are used, the listed observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Displays table of values.
def note_add(
self, evarname, note, replace=False, in_=None)
Add given note for varname or '_dta', or replacing existing note if specified.
Note will be truncated to 67,784 characters if necessary.
Parameters
evarname : str
Name of data variable or 'dta'.
An abbreviation of a variable name is allowed if unambiguous.
note : str
Note should be ascii ('iso-8859-1').
Otherwise, the note will not be saved as intended.
replace : bool (or coercible to bool), optional
Specify that existing note should be replaced.
If replace
is True, in_
must be specified as well.
Otherwise, replace
will be ignored.
Default value is False.
in : int, optional
Note number to replace (>= 1).
Only used if replace
is True.
Returns
None
Side effects
Inserts text as new note or replacement for old note.
def note_drop(
self, evarnames, in_=None)
Drop notes in given numbers for given evarnames.
Parameters
evarnames : str or iterable of str Names of data variable(s) or 'dta'. Abbreviations of variable names are allowed if unambiguous. in : int or iterable of int, optional Note number(s) to drop (>= 1). If `in_' not specified or is None, all notes will be dropped for given evarnames.
Returns
None
Side effects
Deletes notes.
def note_list(
self, evarnames='', in_=None)
List notes in given numbers for given evarnames.
Parameters
evarnames : str or iterable of str Names of data variable(s) or 'dta'. Abbreviations of variable names are allowed if unambiguous. in : int or iterable of int, optional Note number(s) to drop (>= 1). If `in_' not specified or is None, all notes will be dropped for given evarnames.
Returns
None
Side effects
Displays notes.
def note_renumber(
self, evarname)
Inheritance:
Dta
.note_renumber
Remove gaps in note numbers.
Parameters
evarname : str Name of data variable or '_dta'. An abbreviation of a variable name is allowed if unambiguous.
Returns
None
Side effects
Renumbers notes if necessary.
def note_replace(
self, evarname, note, in_)
Inheritance:
Dta
.note_replace
Replace existing note for varname or '_dta'.
Note will be truncated to 67,784 characters if necessary.
Parameters
evarname : str Name of data variable or 'dta'. An abbreviation of a variable name is allowed if unambiguous. note : str Note should be ascii ('iso-8859-1'). Otherwise, the note will not be saved as intended. in : int Note number to replace (>= 1).
Returns
None
Side effects
Inserts text as replacement for old note.
def note_search(
self, text)
Inheritance:
Dta
.note_search
Search in notes for exact matches of given text.
Parameters
text : str
Returns
None
Side effects
Displays notes matching text.
def notes_add(
self, evarname, note, replace=False, in_=None)
Add given note for varname or '_dta', or replacing existing note if specified.
Note will be truncated to 67,784 characters if necessary.
Parameters
evarname : str
Name of data variable or 'dta'.
An abbreviation of a variable name is allowed if unambiguous.
note : str
Note should be ascii ('iso-8859-1').
Otherwise, the note will not be saved as intended.
replace : bool (or coercible to bool), optional
Specify that existing note should be replaced.
If replace
is True, in_
must be specified as well.
Otherwise, replace
will be ignored.
Default value is False.
in : int, optional
Note number to replace (>= 1).
Only used if replace
is True.
Returns
None
Side effects
Inserts text as new note or replacement for old note.
def notes_drop(
self, evarnames, in_=None)
Inheritance:
Dta
.notes_drop
Drop notes in given numbers for given evarnames.
Parameters
evarnames : str or iterable of str Names of data variable(s) or 'dta'. Abbreviations of variable names are allowed if unambiguous. in : int or iterable of int, optional Note number(s) to drop (>= 1). If `in_' not specified or is None, all notes will be dropped for given evarnames.
Returns
None
Side effects
Deletes notes.
def notes_list(
self, evarnames='', in_=None)
Inheritance:
Dta
.notes_list
List notes in given numbers for given evarnames.
Parameters
evarnames : str or iterable of str Names of data variable(s) or 'dta'. Abbreviations of variable names are allowed if unambiguous. in : int or iterable of int, optional Note number(s) to drop (>= 1). If `in_' not specified or is None, all notes will be dropped for given evarnames.
Returns
None
Side effects
Displays notes.
def notes_renumber(
self, evarname)
Inheritance:
Dta
.notes_renumber
Remove gaps in note numbers.
Parameters
evarname : str Name of data variable or '_dta'. An abbreviation of a variable name is allowed if unambiguous.
Returns
None
Side effects
Renumbers notes if necessary.
def notes_replace(
self, evarname, note, in_)
Inheritance:
Dta
.notes_replace
Replace existing note for varname or '_dta'.
Note will be truncated to 67,784 characters if necessary.
Parameters
evarname : str Name of data variable or 'dta'. An abbreviation of a variable name is allowed if unambiguous. note : str Note should be ascii ('iso-8859-1'). Otherwise, the note will not be saved as intended. in : int Note number to replace (>= 1).
Returns
None
Side effects
Inserts text as replacement for old note.
def notes_search(
self, text)
Inheritance:
Dta
.notes_search
Search in notes for exact matches of given text.
Parameters
text : str
Returns
None
Side effects
Displays notes matching text.
def order(
self, varnames, last=False, before=None, after=None, alpha=False)
Change order of varlist.
Any duplicates in varnames will be ignored.
Parameters
varnames : str, or iterable of str
Can be a str containing one varname (e.g. "mpg"),
a str with multiple varnames (e.g. "make price mpg"),
or an iterable of such str
(e.g. ("make", "price", "mpg") or ("make", "price mpg")).
Abbreviations are allowed if unambiguous.
last : bool (or coercible to bool), optional
Signal that specified variables should come last in the
varlist instead of first. Default is False.
May not be combined with before
or after
.
before : str, optional
Name of variable to put the specified variables before.
An abbreviation is allowed if unambiguous.
By default this option is turned off.
May not be combined with last' or
after'
after : str, optional
Name of variable to put the specified variables after.
An abbreviation is allowed if unambiguous.
By default this option is turned off.
May not be combined with last' or
before'
alpha : bool (or coercible to bool), optional
Signal that varlist should be sorted alphabetically
before rearranging. Default is False.
Returns
None
Side effects
Reorders varlist.
def quiet(
self, q=True)
Allow or disallow output messages.
Parameters
q : bool or coercible to bool Default value is True, meaning disallow messages.
Returns
None
Notes
Methods that are primarily designed for output--like describe
,
list
, and summary
--will show output regardless. Setting this
function affects warnings or other 'unexpected' messages.
def rename(
self, oldname, newname)
Replace old variable name with new.
Parameters
oldname : str Single variable name (abbreviation allowed if unambiguous). newname : str New variable name.
Returns
None
Side effects
Replace old data variable name with new.
def replace(
self, id, values, in_=None, if_=None)
Replace values in given data variable.
Parameters
id : int or str
Single variable index (int) or name (str).
For str, an abbreviation is allowed if unambiguous.
values : iterable
Can be a flat iterable like [1, 5, 9, ...] or iterable of
rows, like [[1], [5], [9], ...].
Should have the same number of values as current number of
observations or as implied by in_
and if_
.
in_ : iterable, optional
Used to specify observations replace.
Should be an iterable of int.
Default is all observations.
if_ : function, optional
Used to specify observations replace.
Should be a function taking int and
returning Boolean (or coercible to Boolean).
Default is True for all obs.
Parameters note
If both in_
and if_
are used, the replaced observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Replaces values in given data variable.
def return_list(
self)
Inheritance:
Dta
.return_list
Display any saved results for this dta object.
Returns
None
Side effects
Displays contents of saved results, if any.
def save(
self, address=None, replace=False)
Save current Dta object as dta file.
Parameters
address : str Address of file to save to. Optional if Dta object was created from file or has been saved already, otherwise required. replace : bool, optional Default value is False. True is required to write over existing file.
Returns
None
Side effects
creates or replaces dta file
def set_obs(
self, num_obs)
Increase number of observations in data set.
Parameters
num_obs : int Number of observations to increase to.
Returns
None
Side effects
Changes number of observations. Appends observations with MissingValue instance for numeric variables, "" for string. Marks data as unsorted.
def sort(
self, varnames)
Sort data values according to given variables.
Parameters
varnames : str, or iterable of str Can be a str containing one varname (e.g. "mpg"), a str with multiple varnames (e.g. "make price mpg"), or an iterable of such str (e.g. ("make", "price", "mpg") or ("make", "price mpg")). Abbreviations are allowed if unambiguous.
Returns
None
Side effects
Sorts observations of the data set.
def summ(
self, varnames='', *args, **kwargs)
Summarize data variables.
Summarize specified variable(s), or, if no variables specified, summarize all variables.
Parameters
varnames : str, or iterable of str, optional
Default is none specified (i.e. summarize all).
Can be a str containing one varname (e.g. "mpg"),
a str with multiple varnames (e.g. "make price mpg"),
or an iterable of such str
(e.g. ("make", "price", "mpg") or ("make", "price mpg")).
Abbreviations are allowed if unambiguous.
detail : bool (or coercible to bool)
May not be combined with meanonly
.
meanonly : bool (or coercible to bool)
May not be combined with detail
.
separator : int
Number of summaries to group together with dividing line.
Has no effect
quietly : bool (or coercible to bool)
Create summary, but do not display. Useful if only wanting
to save summary results, to be displayed with return_list
.
weight : str
Single varname (or abbreviation).
May not be combined with other weights.
aweight : str
Single varname (or abbreviation).
May not be combined with other weights.
fweight : str
Single varname (or abbreviation), of an integer variable.
May not be combined with other weights.
iweight : str
Single varname (or abbreviation).
May not be combined with other weights.
May not be combined with detail
option.
in_ : iterable, optional
Used to specify observations to include in summary.
Should be an iterable of int.
Default is all observations.
if_ : function, optional
Used to specify observations to include in summary.
Should be a function taking int and
returning Boolean (or coercible to Boolean).
Default is True for all obs.
Parameters note
Above parameters can be accessed by name.
Otherwise, the parameters appear in the above order.
If both in_
and if_
are used, the summarized observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Displays summary of specified variable(s). Saves the values
from the last summary, which can be displayed with return_list
.
def summarize(
self, varnames='', *args, **kwargs)
Summarize data variables.
Summarize specified variable(s), or, if no variables specified, summarize all variables.
Parameters
varnames : str, or iterable of str, optional
Default is none specified (i.e. summarize all).
Can be a str containing one varname (e.g. "mpg"),
a str with multiple varnames (e.g. "make price mpg"),
or an iterable of such str
(e.g. ("make", "price", "mpg") or ("make", "price mpg")).
Abbreviations are allowed if unambiguous.
detail : bool (or coercible to bool)
May not be combined with meanonly
.
meanonly : bool (or coercible to bool)
May not be combined with detail
.
separator : int
Number of summaries to group together with dividing line.
Has no effect
quietly : bool (or coercible to bool)
Create summary, but do not display. Useful if only wanting
to save summary results, to be displayed with return_list
.
weight : str
Single varname (or abbreviation).
May not be combined with other weights.
aweight : str
Single varname (or abbreviation).
May not be combined with other weights.
fweight : str
Single varname (or abbreviation), of an integer variable.
May not be combined with other weights.
iweight : str
Single varname (or abbreviation).
May not be combined with other weights.
May not be combined with detail
option.
in_ : iterable, optional
Used to specify observations to include in summary.
Should be an iterable of int.
Default is all observations.
if_ : function, optional
Used to specify observations to include in summary.
Should be a function taking int and
returning Boolean (or coercible to Boolean).
Default is True for all obs.
Parameters note
Above parameters can be accessed by name.
Otherwise, the parameters appear in the above order.
If both in_
and if_
are used, the summarized observations
are the numbers in in_
that satisfy if_
.
Returns
None
Side effects
Displays summary of specified variable(s). Saves the values
from the last summary, which can be displayed with return_list
.
def to_list(
self)
Return list of data observations.
Returns
list List of observations, each of which is also a list.
def variable(
self, id)
Get a list of all values of a data variable.
Parameters
id : int or str Single variable index (int) or name (str). For str, an abbreviation is allowed if unambiguous.
Returns
list List of values of the specified data variable.
def xpose(
self, clear=False, varname=False)
Transpose data.
Parameters
clear : Boolean , required The purpose of this parameter is to remind the user that this method replaces the data in the dataset.
Returns
None
Note
This method does not yet support the -promote- option in Stata.
Side effects
Can change almost everything in the data set. Replaces string values with missing. Transposes numeric values in the data, and thus changing number of observations, number of variables, variable names, etc. Removes or replaces existing variable labels, characteristics, display formats, sort info.


Athena (Abstract Schema Definition Language) is a textual DSL aimed to define abstract schemas in a platform-independent way. For doing so Athena reunites concepts of all NoSQL paradigms, based on the U-Schema metamodel. Athena has been designed using Xtext and the Eclipse Modeling Framework. Examples of Athena schemas may be found on the models folder.
Orion (Operations defined over Athena schemas) is a textual DSL aimed to specify operations to be executed over an Athena schema in order to update (evolve) it along with the associated data. Orion has been designed using Xtext and the Eclipse Modeling Framework.
Deimos (Data generation and mapping operations) is a declarative textual language aimed to generate synthetic data.


--- layout: page title: Skills subtitle: TOOLS ---
| Programming Languages | PYTHON | R | MATLAB | BASH PROGRAMMING |
| Modeling / Simulation | SIMULINK |
| Deep Learning | KERAS | PYTORCH | FASTAI |
| Big Data Technology | SPARK |
| Cloud Services | AZURE SERVICES |
| User Interface | RSHINY |
| Miscellaneous | SQL | EXCEL | VBA | GIT | LINUX | DOCKER |


--- layout: slider permalink: /kuiu/ title: KUIU description: A description, my friend. image01: - /images/kuiu/chilcote_pack-system-2.gif image02: - /images/kuiu/chilcote_tent-2.gif show_image02: true image03: - /images/kuiu/chilcote_suspension-rig-2.gif show_image03: true image04: - /images/kuiu/chilcote_sleeping-bag-2.gif show_image04: true ---
KUIU is a mountain hunting clothing and supply company based out of California. To demonstrate the assembly and action of select products, we arranged stop motion loops that live on product description pages. These added more insight to the item such as capacity, ease-of-use, and modularity.


READ_FILE
FunctionReads a file line-by-line and returns it in a table. This function is used in the FROM
clause of a
SELECT
statement and can participate in joins as if it were a table.
READ_FILE(file-path, [file-encoding])
| Column name | Example value |
|---|---|
number |
1 |
line |
"First line of the file" |
-- Returns a table containing the last 50 lines
-- in "file.txt" in reverse order.
SELECT *
FROM READ_FILE('C:\temp\file.txt')
ORDER BY number DESC
LIMIT 50;
-- Returns a table containing the contents of
-- "ShiftJIS.txt", which is read using the Japanese
-- Shift-JIS encoding (code page 932).
SELECT * FROM READ_FILE('C:\ShiftJIS.txt', 932);


Select Movie
The Simpsons
Ala bala
Inception
}
Vineri
Sambata
Duminica
Available Seat
Selected Seat
Price: 0$
Selected seat price: 0$


Amazon workers strike on ‘Black Friday’
by Agency ReportHundreds of Amazon workers in Germany walked off the job as the US online retailer kicked off its “Black Friday” sales bonanza, escalating a long-simmering battle for better pay and working conditions.
The strike called by the powerful Verdi union is set to last until Tuesday morning and will also cover “Cyber Monday”, another extravaganza of online discounts in what is a crucial sales period for Amazon.
Verdi spokeswoman Eva Voelpel told AFP “several hundred” employees had started the stoppage at Amazon distribution centres in Leipzig, Bad Hersfeld, Koblenz, Rheinberg, Werne and Graben.
“Their work cannot be had at rock-bottom prices,” Verdi said in a statement, demanding a collective labour agreement to ensure “a living wage and good, healthy jobs”.
The union accused Amazon of “withholding basic rights” from staff and of making them work “under extreme pressure”.
“As a result, many employees become ill,” Verdi said.
Amazon played down the strike’s impact, saying “packages will arrive on time”.
The company has long resisted the union’s call for labour negotiations, defending its work environment and insisting that is “one of the best employers in the logistics industry”.
“We pay at the upper end of what is usual for comparable work, we offer additional benefits and review wages annually,” the company said.
The majority of its 13,000 employees in 13 logistics centres across Germany will be working “as normal”, it added.
Amazon has been hit by repeated strikes in Germany and other countries in recent years.
Last year’s “Black Friday” event saw stoppages by workers in Spain, Germany and Britain.
(AFP)


Logan Paul admits KSI rivalry was fake as third rematch ruled out
Logan Paul claimed his fierce rivalry with KSI was "all for show" and for "selling" after losing their rematch
by Rich Jones, https://www.mirror.co.uk/authors/rich-jones/Logan Paul claimed his rivalry with KSI was fake and "all for show" immediately after losing their rematch.
KSI edged a narrow split decision, over a year after their majority draw in Manchester, to settle their long-running feud.
The pair have traded verbal blows in the build-up but shared an embrace after the result was announced and both spoke of their respect for one another.
The victorious Brit dismissed any talk of a trilogy by declaring he's "done" and "onto the next thing" - and Paul outlined his respect for his rival which he says was always present despite "selling" the clash with their war of words.
"I just want to say fair play to JJ," Paul said in the ring after the fight.
"You're one of the toughest people I know. You've earned everything you've got in life.
"You had my respect before this. It's all for show, it's all for selling dude.
"You're one of the toughest people I know and I wish you all the best."
KSI, meanwhile, thanked Paul for creating an entertaining fight and "making him work".
He said: "You know what, we've gotta have some respect.

"You made me work today and you made me work last year as well.
"Thank you for a good fight, brother."
Asked what changed from the first fight, the triumphant KSI said: KSI: "KSI last time was scared. I was scared to fight, I was scared to touch him, I was scared to get close to him.
"This time I just went in. I just kept going and going.
"Obviously they saw how much bigger he was, they saw his physique.
"I constantly just kept going and going. I want to thank my team, who helped me so much.
"I've done it. I'm victorious."