Skip to content

panel_agg_grouped() #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
atecon opened this issue Aug 28, 2024 · 1 comment
Open

panel_agg_grouped() #6

atecon opened this issue Aug 28, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@atecon
Copy link
Owner

atecon commented Aug 28, 2024

What it does?

  • This function computes aggregation statistics for each distinct value of 'factor', e.g.panel unit
function void panel_agg_grouped (const list Targets,
                                                              const strings Metrics,
                                                              const series factor)
    /* Print summary statistics for each metric in 'Metrics' for each
       panel unit in 'factor'. Each table refers to some metric.
       For a given metric a table (matrix) will be
       printed. Rows refer to the factor units and columns to the statistics of
       each target series. */

    strings factor_names = strvals(factor)  # TODO: check for existence
    strings column_labels = varnames(Targets)

    loop foreach i Metrics
        result = aggregate(Targets, factor, "$i")[,3:] # disregard "id" and "nobs" columns
        rnameset(result, factor_names)  # TODO: only if present
        cnameset(result, column_labels)

        printf "\n*** Summary statistics for metric '%s' ***\n\n", "$i"
        printf "%16.2f\n", result
    endloop
end function

Example output is

*** Summary statistics for metric 'mean' ***

        d_production      d_building       d_permits        d_income    d_houseprice      d_interest  d_unemployment
GER            -0.04           -0.09           -0.36            0.09            0.02           -0.01           -0.00
FRA            -0.01            0.00           -0.08            0.12            0.11           -0.01           -0.00
ITA             0.13             nan           -0.69           -0.01           -0.06           -0.00           -0.00
ESP            -0.52           -0.19           -1.38            0.06            0.11           -0.01           -0.01
NED             0.08            0.12            0.10            0.03            0.24           -0.01           -0.01
BEG             0.01           -0.01            0.03            0.02            0.15           -0.01           -0.00
AUT             0.16            0.19           -0.01            0.01            0.15           -0.00            0.00
POR            -0.78           -0.74           -1.25            0.01             nan           -0.01            0.00
GRE              nan             nan            0.41            0.00            0.20           -0.02           -0.00
IRE              nan             nan           -0.37            0.02            0.23            0.00           -0.02

Todo

  • Think about a better function name
  • But return each matrix as a bundle item
  • Add a print function for convenience only
  • Add a parameter bundle, e.g. for setting the number of digits or so
@atecon atecon added the enhancement New feature or request label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants
@atecon and others