[ PcGive home | Index ]

database.oxh

Database : Sample class reference

Database function members (public by default)
 Append(const mNew, const asNew, ...)
 Appends variable(s) to the database.
 Create( ...)
 Creates the database by setting the sample (the database must be empty to start).
 Database()
 Constructor, creates an empty database by calling `Database::Empty` and sets selection mode to SAM_ALLVALID.
 DeSelect()
 Remove the current variable and sample selection.
 DeSelectByIndex(const iSel)
 Removes variable(s) from the selection.
 DeSelectByName(const sVar, const iGroup, const iLag)
 Removes variable(s) from the selection.
 Deterministic(const fCseason)
 Appends constant, trend and seasonals to the database.
 Empty()
 Empties the database.
 FindSelection(const sVar, const iLag)
 Returns the selection index of the specified variable with the specified lag, or -1 if it is not selected.
 ForceSelSample(const iYear1, const iPeriod1, const iYear2, const iPeriod2)
 Force a selection sample (fixed frequency database).
 ForceSelSampleByIndex(const iT1, const iT2)
 Forces a selection sample by observation indices.
 GetAll()
 Gets the data matrix m_mData.
 GetAllNames()
 Gets the variable names as an array of strings.
 GetDateByIndex(const iT1)
 Gets the date of an observation.
 GetDates()
 Gets the first column if the database is dated.
 GetDbName()
 Gets the database name.
 GetGroup(const iGroup)
 Gets the data matrix for the specified group.
 GetGroupLag(const iGroup, const iLag1, const iLag2)
 Gets the data matrix for the specified group between specific lag lengths.
 GetGroupLagNames(const iGroup, const iLag1, const iLag2, const aasNames)
 Gets the variable names for the specified group between specific lag lengths.
 GetGroupNames(const iGroup, const aasNames)
 Gets the variable names for the specified group.
 GetIndexByDate(const dDate1)
 returns the index closest to the specified date.
 GetIndexByDates(const dDate1, const dDate2)
 returns the start and end indices of the specified period as an array of two integers.
 GetMaxGroupLag(const iGroup)
 Gets the longest lag length in the group.
 GetMaxLag()
 Use `Database::GetMaxSelLag`.
 GetMaxSelLag()
 Gets the longest lag length in the selection.
 GetObsLabel( sVar, const iT)
 Gets the text representation of an observation.
 GetSample()
 Gets the database sample text.
virtual GetSampleByIndex(const iT1, const iT2)
 Gets the subsample text.
 GetSelEnd()
 Gets the last observation of the selection.
 GetSelInfo()
 Gets the selection info
 GetSelSample()
 Gets the text of the selection sample.
 GetSelSampleMode()
 Get the sample selection mode.
 GetSelStart()
 Gets the first observation of the selection.
 GetVar(const sName)
 Gets the named variable(s).
 GetVarByIndex(const iVar)
 Gets the variable(s) from specified column index (indices).
 GetVarChoices(const sVar)
 Gets the choice set of a variable by name.
 GetVarChoicesByIndex(const iVar)
 Gets the choice set of a variable by column index.
 GetVarCount()
 Get the number of variables in the database.
 GetVarIndex(const sName)
 Gets index(indices) of variable(s) from specified name or names.
 GetVarNameByIndex(const iVar)
 Gets the variable(s) names from specified column index (indices).
 GetVarType(const sVar)
 Gets the variable type.
 GetVarTypeByIndex(const iVar)
 Gets the variable type.
 Grow(const cTadd)
 Grows the database sample size.
 Info()
 Prints database information.
 IsDated()
 Returns TRUE if the database is dated (the first column is of type DB_DATE.
 IsEmpty()
 Check if the database is empty.
 Load(const file)
 Loads a database from the specified file into the object.
 LoadCsv(const file)
 Use `Database::Load`.
 LoadDht(const file, const iYear1, const iPeriod1, const iFreq)
 Obsolete format.
 LoadDta(const file, const iYear1, const iPeriod1, const iFreq)
 Use `Database::Load`.
 LoadFmtVar(const file)
 Loads a database from a formatted text file into the object.
 LoadIn7(const file)
 Use `Database::Load`.
 LoadObs(const file, const cVar, const cObs, const iYear1, const iPeriod1, const iFreq, const fOffendMis)
 Loads a database from a text file into the object, ordered by observation.
 LoadVar(const file, const cVar, const cObs, const iYear1, const iPeriod1, const iFreq, const fOffendMis)
 Loads a database from a text file into the object, ordered by variable.
 LoadXls(const file)
 Obsolete format.
 LoadXlsx(const file)
 Use `Database::Load`.
 Recode(const sVar, ...)
 Recodes elements of a variable.
 Remove(const sName)
 Remove variable(s) form the database.
 RemoveObsIf(const vRemove)
 Remove observation(s) form the database.
 Rename(const sNewName, const sOldName)
 Renames variable(s).
 Renew(const mNew, const asNew, ...)
 Renews the observations on the named variable(s).
 RenewBlock(const mNew, const iVarIndex)
 Changes observations on the specified columns without checking.
 Save(const file)
 Saves the database to the specified file.
 SaveCsv(const file)
 Use `Database::Save`.
 SaveFmtVar(const file)
 Saves the database to a formatted text file.
 SaveIn7(const file)
 Use `Database::Save`.
 SaveObs(const file)
 Saves the database to a text file, stored by observation.
 SaveVar(const file)
 Saves the database to a text file, stored by variable.
 SaveXls(const file)
 Obsolete format.
 SaveXlsx(const file)
 Use `Database::Save`.
 Select(const iGroup, const aSel)
 Select variables by name into a group.
 SelectByIndex(const iGroup, const iVar, const iLag0, const iLag1)
 Select variables by name into a group.
 SetDates(const vDates)
 Makes the database dated by setting the first column to DB_DATE
 SetDbName(const sName)
 Sets the database name.
 SetSample(const iYear1, const iPeriod1, const iYear2, const iPeriod2)
 Obsolete: use `Database::SetSelSample`.
 SetSelDates(const iYear1, const iMonth1, const iDay1, const iYear2, const iMonth2, const iDay2)
 Set a selection sample by year, month, day (dated database).
 SetSelInfo(const aInfo)
 Sets the selection info
 SetSelSample(const iYear1, const iPeriod1, const iYear2, const iPeriod2)
 Select a selection sample (fixed frequency database).
 SetSelSampleByDates(const dDate1, const dDate2)
 Set a selection sample by date values (dated database).
 SetSelSampleByIndex(const iT1, const iT2)
 Set a selection sample by observation indices.
 SetSelSampleMode(const iMode)
 Set the sample selection mode.
 SetVar(const vNew, const sName)
 Creates variable(s) in the database.
 SetVarChoices(const sVar, const asChoices)
 Sets the variable type to DB_CHOICE by name.
 SetVarChoicesByIndex(const iVar, const asChoices)
 Sets the variable type to DB_CHOICE by column index.
 SetVarType(const sVar, const iType)
 Sets the variable type by name.
 SetVarTypeByIndex(const iVar, const iType)
 Sets the variable type by column index.
 Shrink(const cTdel)
 Shrinks the database sample size.
 SortBy(const sX)
 Sorts the database by the specified variable(s).
 Tabulate(const sX, ...)
 Sorts the database by the specified variable(s).

Database data members (protected by default)
 m_aasChoices
 
 m_mData
 
 m_sDbName
 
 m_mLagsel
 
 m_asNames
 
 m_iSampleSelMode
 
 m_mSelgroup
 
 m_iT1sel
 
 m_iT2sel
 
 m_mVarsel
 
 m_vVarType
 

Database enum members (protected by default)
public:{DB_DOUBLE, DB_DATE, DB_CHOICE}
 variable types
public:{SAM_ALLVALID, SAM_ENDSVALID, SAM_ANYVALID}
 sample selection modes

Sample class reference

Sample function members (public by default)
 GetFrequency()
 Gets the frequency.
 GetIndex(const iYear, const iPeriod)
 Gets the index in the sample of iYear1(iPeriod1).
 GetPeriod1()
 Gets the start period.
 GetPeriod2()
 Gets the end period.
 GetSize()
 Gets the sample size.
 GetYear1()
 Gets the start year.
 GetYear2()
 Gets the end year.
 ObsPeriod( obs)
 Gets the period of the sample index, so ObsPeriod(0) equals GetPeriod1().
 ObsYear( obs)
 Gets the year of the sample index, so ObsYear(0) equals GetYear1().
 Resample(const iFreq, const iYear1, const iPeriod1)
 Changes the sample

Sample data members (protected by default)
 m_iFreq
 
 m_iPeriod1
 
 m_iPeriod2
 
 m_iYear1
 
 m_iYear2
 

Database::Append(const mNew, const asNew, ...)
Appends variable(s) to the database.
Parameters
mNew matrix[][k]
sName string or array[k] of strings.
iT1 (optional) first observation to renew from (default is 0).
Comments
It is an error if the variable already exists (use Renew or SetVar instead), or if the new variable has more observations than the database (use Grow first or SetVar instead).

Database::Create( ...)
Creates the database by setting the sample (the database must be empty to start).
Parameters
cT int, sample size
iFreq int, frequency
iYear1 int, start year
iPeriod1 start period
iYear2 int, end year
iPeriod2 int, end period
Comments
Can be called in three ways: Create(cT) Create(iFreq, iYear1, iPeriod1, cT) Create(iFreq, iYear1, iPeriod1, iYear2, iPeriod2)

Database::Database()
Constructor, creates an empty database by calling Empty and sets selection mode to SAM_ALLVALID.

Database::DeSelect()
Remove the current variable and sample selection.

Database::DeSelectByIndex(const iSel)
Removes variable(s) from the selection.
Parameters
iSel int, selection indices of variable to remove

Database::DeSelectByName(const sVar, const iGroup, const iLag)
Removes variable(s) from the selection.
Parameters
sVar string, name of variable to remove
iGroup int, group identifier.
iLag int, lag length

Database::Deterministic(const fCseason)
Appends constant, trend and seasonals to the database.
Parameters
-1: no seasonals; 0: n Seasonals Season, Season_1, ...; 1: n centred seasonals CSeason, CSeason_1; 2: 1 seasonal called Seasonal 3: 1 centred seasonal called CSeasonal.
iCseason

Database::Empty()
Empties the database.

Database::FindSelection(const sVar, const iLag)
Returns the selection index of the specified variable with the specified lag, or -1 if it is not selected.
Parameters
sVar string, name of variable
iLag int, lag length
Returns
-1 if not found, otherwise selection index

Database::ForceSelSample(const iYear1, const iPeriod1, const iYear2, const iPeriod2)
Force a selection sample (fixed frequency database).
Parameters
iYear1 int, start year of selection, use -1 for earliest year and period
iPeriod1 int, start period of selection
iYear2 int, end year of selection, use -1 for latest year and period
iPeriod2 int, end period of selection
Returns
Number of observations in the sample.
Comments
No validity check is run, except that the start must not be after the end.

Database::ForceSelSampleByIndex(const iT1, const iT2)
Forces a selection sample by observation indices.
Parameters
iT1 int, first observation
iT2 int, last observation
Returns
Number of observations in the sample.
Comments
No validity check is run, except that the start must not be after the end.

Database::GetAll()
Gets the data matrix m_mData.

Database::GetAllNames()
Gets the variable names as an array of strings.

Database::GetDateByIndex(const iT1)
Gets the date of an observation.

Database::GetDates()
Gets the first column if the database is dated.
Returns
first column if the database is dated, <> otherwise.

Database::GetDbName()
Gets the database name.

Database::GetGroup(const iGroup)
Gets the data matrix for the specified group.
Parameters
iGroup group identifier.
Returns
matrix[m_iT2sel-m_iT1sel+1][..] with data.
Comments
Can only be used after variables and sample have been selected.

Database::GetGroupLag(const iGroup, const iLag1, const iLag2)
Gets the data matrix for the specified group between specific lag lengths.
Parameters
iGroup group identifier.
iLag1 start lag
iLag2 end lag
Returns
matrix[m_iT2sel-m_iT1sel+1][..] with data.
Comments
Can only be used after variables and sample have been selected.

Database::GetGroupLagNames(const iGroup, const iLag1, const iLag2, const aasNames)
Gets the variable names for the specified group between specific lag lengths.
Parameters
iGroup group identifier.
iLag1 start lag
iLag2 end lag
aasNames in: reference to variable, out: array of strings
Returns
only returns a value if aasNames 0: variable names, or 1: base names, each base name followed by lag specification.
Comments
Can only be used after variables have been selected.

Database::GetGroupNames(const iGroup, const aasNames)
Gets the variable names for the specified group.
Parameters
iGroup group identifier.
aasNames in: reference to variable, out: array of strings
Returns
as GetGroupLagNames
Comments
Can only be used after variables have been selected.

Database::GetIndexByDate(const dDate1)
returns the index closest to the specified date.

Database::GetIndexByDates(const dDate1, const dDate2)
returns the start and end indices of the specified period as an array of two integers.

Database::GetMaxGroupLag(const iGroup)
Gets the longest lag length in the group.

Database::GetMaxLag()
Use GetMaxSelLag

Database::GetMaxSelLag()
Gets the longest lag length in the selection.

Database::GetObsLabel( sVar, const iT)
Gets the text representation of an observation.
Parameters
sVar string
Returns
string

Database::GetSample()
Gets the database sample text.
Returns
string

virtual Database::GetSampleByIndex(const iT1, const iT2)
Gets the subsample text.
Parameters
of a sample range)
iT1 int, first observation index
iT2 int, last observation index (or -1 for just a sample point, instead
Returns
string

Database::GetSelEnd()
Gets the last observation of the selection.

Database::GetSelInfo()
Gets the selection info
Returns
array[5] { matrix[1][k] db indices, matrix[1][k] variable group identifier, matrix[1][k] lag lengths, start obs, end obs }.

Database::GetSelSample()
Gets the text of the selection sample.

Database::GetSelSampleMode()
Get the sample selection mode.
Returns
one of SAM_ALLVALID, SAM_ENDSVALID, SAM_ANYVALID, SAM_ANYVALID+1.

Database::GetSelStart()
Gets the first observation of the selection.

Database::GetVar(const sName)
Gets the named variable(s).

Database::GetVarByIndex(const iVar)
Gets the variable(s) from specified column index (indices).

Database::GetVarChoices(const sVar)
Gets the choice set of a variable by name.
Parameters
sVar string
Returns
{} or array of strings mapping values (the index) to labels

Database::GetVarChoicesByIndex(const iVar)
Gets the choice set of a variable by column index.
Parameters
iVar column index
Returns
{} or array of strings mapping values (the index) to labels

Database::GetVarCount()
Get the number of variables in the database.
Returns
the number of variables in the database (columns of m_mData).

Database::GetVarIndex(const sName)
Gets index(indices) of variable(s) from specified name or names.

Database::GetVarNameByIndex(const iVar)
Gets the variable(s) names from specified column index (indices).

Database::GetVarType(const sVar)
Gets the variable type.
Parameters
sVar string or array of strings
Returns
variable type(s) consisting of DB_DOUBLE,DB_DATE,DB_CHOICE

Database::GetVarTypeByIndex(const iVar)
Gets the variable type.
Parameters
iVar column index or indices
Returns
variable type(s) consisting of DB_DOUBLE,DB_DATE,DB_CHOICE

Database::Grow(const cTadd)
Grows the database sample size.
Parameters
in: int, number of observations to grow database sample by (> 0: cTadd observations are added at the end; < 0: -cTadd observations are added at the beginning).
cTadd
Comments
Newly created onbservations are set to .NaN; also moves the selection sample.

Database::Info()
Prints database information.

Database::IsDated()
Returns TRUE if the database is dated (the first column is of type DB_DATE.

Database::IsEmpty()
Check if the database is empty.
Returns
TRUE if empty.

Database::Load(const file)
Loads a database from the specified file into the object.
Parameters
file, string with filename, the filetype is derived from the filename extension.
Returns
FALSE if loading failed, TRUE otherwise.

Database::LoadCsv(const file)
Use Load

Database::LoadDht(const file, const iYear1, const iPeriod1, const iFreq)
Obsolete format.

Database::LoadDta(const file, const iYear1, const iPeriod1, const iFreq)
Use Load

Database::LoadFmtVar(const file)
Loads a database from a formatted text file into the object.
Parameters
file, string with filename
Returns
FALSE if loading failed, TRUE otherwise.

Database::LoadIn7(const file)
Use Load

Database::LoadObs(const file, const cVar, const cObs, const iYear1, const iPeriod1, const iFreq, const fOffendMis)
Loads a database from a text file into the object, ordered by observation.
Parameters
file, string with filename
Returns
FALSE if loading failed, TRUE otherwise.

Database::LoadVar(const file, const cVar, const cObs, const iYear1, const iPeriod1, const iFreq, const fOffendMis)
Loads a database from a text file into the object, ordered by variable.
Parameters
file, string with filename
Returns
FALSE if loading failed, TRUE otherwise.

Database::LoadXls(const file)
Obsolete format.

Database::LoadXlsx(const file)
Use Load

Database::Recode(const sVar, ...)
Recodes elements of a variable.
Parameters
sVar string, name of variable to recode
... comma-separated pairs of recoding values: old-value, new value
Returns
0 if the variable is not found.
Comments
old-value can be a scalar or a vector with two arguments, specifying a closed interval.

Database::Remove(const sName)
Remove variable(s) form the database.
Parameters
sName string or array of strings.

Database::RemoveObsIf(const vRemove)
Remove observation(s) form the database.
Parameters
vRemove vector[T] with 0-1 to indicate if observation should be removed, T is database sample size.

Database::Rename(const sNewName, const sOldName)
Renames variable(s).

Database::Renew(const mNew, const asNew, ...)
Renews the observations on the named variable(s).
Parameters
mNew matrix[][k]
sName string or array[k] of strings.
iT1 (optional) first observation to renew from (default is 0).
Comments
If a variable is not in the database it is appended. The database sample size is not changed by Renew, use Grow for this. If a variable already exist, and the new version is shorter than the database, then the remaing values will be unchanged.

Database::RenewBlock(const mNew, const iVarIndex)
Changes observations on the specified columns without checking.
Parameters
mNew matrix[][]
iVarIndex database index of first variable to renew.

Database::Save(const file)
Saves the database to the specified file.
Parameters
file, string with filename, the filetype is derived from the filename extension.
Returns
FALSE if saving failed, TRUE otherwise.

Database::SaveCsv(const file)
Use Save

Database::SaveFmtVar(const file)
Saves the database to a formatted text file.
Parameters
file, string with filename
Returns
FALSE if saving failed, TRUE otherwise.

Database::SaveIn7(const file)
Use Save

Database::SaveObs(const file)
Saves the database to a text file, stored by observation.
Parameters
file, string with filename
Returns
FALSE if saving failed, TRUE otherwise.

Database::SaveVar(const file)
Saves the database to a text file, stored by variable.
Parameters
file, string with filename
Returns
FALSE if saving failed, TRUE otherwise.

Database::SaveXls(const file)
Obsolete format.

Database::SaveXlsx(const file)
Use Save

Database::Select(const iGroup, const aSel)
Select variables by name into a group.
Parameters
followed by start_lag, end_lag (e.g. {"CONS", 0, 3, "Constant", "INC",0,1}
iGroup int, group identifier (e.g. PcGIVE::Y_VAR)
aSel array of variable names, optionally
Comments
Invalidates the selection sample.

Database::SelectByIndex(const iGroup, const iVar, const iLag0, const iLag1)
Select variables by name into a group.
Parameters
iGroup int, group identifier
iVar int or vector[k] column index or indices
iLag0 common start lag or vector[k] with starting lag lengths
iLag1 common end lag or vector[k] with ending lag lengths
Comments
Invalidates the selection sample.

Database::SetDates(const vDates)
Makes the database dated by setting the first column to DB_DATE or replacing the existing DB_DATE column.
Parameters
vDates vector with date values for each observation.

Database::SetDbName(const sName)
Sets the database name.

Database::SetSample(const iYear1, const iPeriod1, const iYear2, const iPeriod2)
Obsolete: use SetSelSample

Database::SetSelDates(const iYear1, const iMonth1, const iDay1, const iYear2, const iMonth2, const iDay2)
Set a selection sample by year, month, day (dated database).
Parameters
iYear1 int, start year of selection
iMonth1 int, start month of selection
iDay1 int, start day of selection
iYear2 int, end year of selection
iMonth2 int, end month of selection
iDay2 int, end day of selection
Returns
Number of observations in the sample.
Comments
Checks, and possibly adjusts, sample according to current sample selection mode (see SetSelSampleMode).

Database::SetSelInfo(const aInfo)
Sets the selection info
Parameters
matrix[1][k] lag lengths, start obs, end obs }.
asInfo array[5] { matrix[1][k] db indices, matrix[1][k] variable group identifier,

Database::SetSelSample(const iYear1, const iPeriod1, const iYear2, const iPeriod2)
Select a selection sample (fixed frequency database).
Parameters
iYear1 int, start year of selection, use -1 for earliest year and period
iPeriod1 int, start period of selection
iYear2 int, end year of selection, use -1 for latest year and period
iPeriod2 int, end period of selection
Returns
Number of observations in the sample.
Comments
Checks, and possibly adjusts, sample according to current sample selection mode (see SetSelSampleMode).

Database::SetSelSampleByDates(const dDate1, const dDate2)
Set a selection sample by date values (dated database).
Parameters
dDate1 date value, start date (-1 is earliest)
dDate2 date value, end date (-1 is latest)
Returns
Number of observations in the sample.
Comments
Checks, and possibly adjusts, sample according to current sample selection mode (see SetSelSampleMode).

Database::SetSelSampleByIndex(const iT1, const iT2)
Set a selection sample by observation indices.
Parameters
iT1 int, first observation
iT2 int, last observation
Returns
Number of observations in the sample.
Comments
Checks, and possibly adjusts, sample according to current sample selection mode (see SetSelSampleMode).

Database::SetSelSampleMode(const iMode)
Set the sample selection mode.
Parameters
SAM_ENDSVALID (the start and end must be fully available, but in between missing values arte allowed), SAM_ANYVALID (any observation may be missing), SAM_ANYVALID+1 (trailing sample without any missing values)
iMode one of SAM_ALLVALID (leading sample without missing values),
Returns
Number of observations in the sample.

Database::SetVar(const vNew, const sName)
Creates variable(s) in the database.
Parameters
mNew matrix[][k]
sName string or array[k] of strings.
Comments
If the database is empty, an annual database is created first. If necessary, the database sample size is extended to accommodate the new data. If the new variable is shorter than the database, it will be padded with missing values.

Database::SetVarChoices(const sVar, const asChoices)
Sets the variable type to DB_CHOICE by name.
Parameters
sVar string
asChoices array of strings mapping values (the index) to labels

Database::SetVarChoicesByIndex(const iVar, const asChoices)
Sets the variable type to DB_CHOICE by column index.
Parameters
iVar column index or indices
asChoices array of strings mapping values (the index) to labels

Database::SetVarType(const sVar, const iType)
Sets the variable type by name.
Parameters
sVar string or array of strings
iType one of DB_DOUBLE,DB_DATE,DB_CHOICE

Database::SetVarTypeByIndex(const iVar, const iType)
Sets the variable type by column index.
Parameters
iVar column index or indices
iType one of DB_DOUBLE,DB_DATE,DB_CHOICE

Database::Shrink(const cTdel)
Shrinks the database sample size.
Parameters
in: int, number of observations to remove (> 0: removed from the end; < 0: -cTdel observations removed from the beginning).
cTdel
Comments
cTdel exceeds the current database sample size, this amounts to calling Empty

Database::SortBy(const sX)
Sorts the database by the specified variable(s).
Parameters
sX string, variable name or array with names

Database::Tabulate(const sX, ...)
Sorts the database by the specified variable(s).
Parameters
sX string, first variable name or array with names
sY string, (optional) second variable name or array with names
sOption string or array of strings, (optional) "%" to print percentages instead of counts

Sample::GetFrequency()
Gets the frequency.

Sample::GetIndex(const iYear, const iPeriod)
Gets the index in the sample of iYear1(iPeriod1).

Sample::GetPeriod1()
Gets the start period.

Sample::GetPeriod2()
Gets the end period.

Sample::GetSize()
Gets the sample size.

Sample::GetYear1()
Gets the start year.

Sample::GetYear2()
Gets the end year.

Sample::ObsPeriod( obs)
Gets the period of the sample index, so ObsPeriod(0) equals GetPeriod1().

Sample::ObsYear( obs)
Gets the year of the sample index, so ObsYear(0) equals GetYear1().

Sample::Resample(const iFreq, const iYear1, const iPeriod1)
Changes the sample