<jupyter_start><jupyter_text>Examples on using MTSDataModel  Load modules<jupyter_code>import sys
sys.path.insert(0,r'../src/')
import MTSDataModel as mts
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import rpy2
import warnings
warnings.filterwarnings('ignore')<jupyter_output><empty_output><jupyter_text>Get data<jupyter_code>filename = 'sample_data.csv'
colnames = {'level1':'Variable', 'level2':'Country', 'value':'Value','index':'Date'}
do = mts.MTSDataModel(filepath=filename, colnames=colnames)
do.ReturnDf().head()<jupyter_output><empty_output><jupyter_text>Demonstate variable and entity selectionsWe'll demonstate how variables and entities are selected into methods that operate on the underlying data frame. The logic in other moethods is the same as in here with method GetVaribales() that just displays chosen variables.<jupyter_code># Get variable StockPrices for entities AUT, DEU, and FIN 
do.GetVariables(['StockPrices']).head(2)
# Get variable StockPrices and GDP by implicitly selecting entities.
# GDP not present for AUT, hence what will be returned are variables
# for DEU and FIN only!
do.GetVariables(['StockPrices', 'GDP']).head(2)
# When entity list is passed in explicitly, it is required that 
# inputted variables are present for all entities, If this is not
# the case, an error will be thrown.
do.GetVariables(['StockPrices', 'GDP'], entities=['FIN', 'AUT']).head(2)
# Variables only for FIN.
do.GetVariables(['StockPrices', 'GDP', 'Inflation'], entities=['FIN']).head(2)
# This will throw an error: variable Credit does not exist in data.
do.GetVariables(['Credit'])<jupyter_output><empty_output><jupyter_text>Pre-processing  Deflate<jupyter_code># Defaltes variable StockPrices for al entities for which variables
# StockPrices and Inflation are present 
do.DeflateVariables(['StockPrices'], infvar='Inflation')
do.ReturnDf().head(2)<jupyter_output><empty_output><jupyter_text>De-trend<jupyter_code># StockPrices_def available for AUT, DEU, and FIN. GDP available only DEU and FIN
# With below implicit selection varibales would get de-trended only for DEU and FIN.
#do.DetrendVariables(['StockPrices_def','GDP'], difftype = 'ld')

# This will result in error as GDP not available for AUT
#do.DetrendVariables(['StockPrices_def','GDP'], entities=['AUT','DEU','FIN'], difftype = 'ld')

# To de-trend StockPrices_def for AUT, DEU, and FIN as well as GDP for
# DEU and FIN. We can do two implicit entities selections:
do.DetrendVariables(['StockPrices_def'], dttype='ld1')
do.DetrendVariables(['GDP'], dttype='ld1')

# Simple logs
do.DetrendVariables(['GDP'], dttype='lg')<jupyter_output><empty_output><jupyter_text>HP filtering<jupyter_code>do.HPFiltering(['GDP_lg'], lamb=1600)
do.HPFiltering(['GDP_lg'], lamb=1600, minobsamount=40, expanding='expanding')
do.PlotVariables(['GDP_lg','GDP_lg_hptr','GDP_lg_hptr_exp'],['DEU'])<jupyter_output><empty_output><jupyter_text>Wavelet MRA decompositions<jupyter_code>do.MRADecomposition(variables = ['StockPrices_def_ld1'], entities=['FIN'], levels=6, minobsamount=40, expanding='expanding')
do.MRADecomposition(variables = ['StockPrices_def_ld1'], entities=['FIN'], levels=6, minobsamount=40)
do.PlotVariables(['StockPrices_def_ld1_wl4', 'StockPrices_def_ld1_wl4_exp'],['FIN'])<jupyter_output><empty_output><jupyter_text>Dimension reduction<jupyter_code>do.ReduceVariableDimension(suffix='PC', variables=['StockPrices_def_ld1', 'GDP_ld1'], entities = ['FIN','DEU'])<jupyter_output><empty_output><jupyter_text>Sum variables<jupyter_code>variables = ['GDP_ld1', 'StockPrices_def_ld1']
do.SumVariables(variables, name="gdp+stock")
do.ReturnDf().head(2)<jupyter_output><empty_output><jupyter_text>Plot<jupyter_code>fig = plt.figure(figsize=(15,7))
ax = fig.add_subplot(1,1,1)
do.PlotVariables(variables=['StockPrices_def_ld1', 'GDP_ld1','PC', 'StockPrices_def_ld1_wl5'], entities=['FIN'], ax=ax)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13627101375445747, 'fraction_numerical': 0.012226184411614875, 'mean_word_length': 9.017857142857142, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '607651', 'license': 'MIT', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1321, 'n_words': 305, 'path': 'examples/sample_examples.ipynb', 'repo_name': 'NoobQuant/MTSDataModel', 'size': '3926'}