Hi Andrew,
To create a time series from a structure where each component represents monthly regression data, follow these steps to organize and export the data into Excel:Steps to Create a Time Series
1. Initialize Data Storage:
- Create an empty cell array or table to store the extracted data for each month and country.
2. Loop Through the Structure:
- Iterate over each month in your "regression_structure".
- For each month, iterate over each country in the "beta_multi" structure.
3. Extract and Organize Data:
- Extract relevant fields such as "rep_industries", "rep_countries", and "beta_multi" for each month and country.
- Store this information in a row of your data storage.
4. Export to Excel:
- Use MATLAB’s "writetable" function to export the organized data to an Excel file.
Example Code
Here is a simplified example:
current_month = regression_structure(i);
countries = fieldnames(current_month.beta_multi);
for j = 1:length(countries)
rep_industries = current_month.rep_industries;
rep_countries = current_month.rep_countries;
beta_data = current_month.beta_multi.(country);
data = [data; {i, country, rep_industries, rep_countries, beta_data}];
data_table = cell2table(data, 'VariableNames', {'Month', 'Country', 'RepIndustries', 'RepCountries', 'BetaData'});
writetable(data_table, 'regression_time_series.xlsx');
I hope this helps!