Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to construct hierarchical concatenation of strings

    Click image for larger version

Name:	Screenshot 2024-02-25 at 20.44.44.png
Views:	2
Size:	134.3 KB
ID:	1744548
    Hi everyone,

    I'm collecting information from Eurostat's codes for Combined Nomenclature.
    The example shows the first few rows of a given year.
    The dataset contains product classes, headers, etc (i.e. 2-4-6-8 digit codes), with the most detailed level being 8-digit codes.
    I'm looking to create a text description for each 8-digit code.
    In particular, text descriptions are structured as follows: (i) a text description, (ii) one layer below are extensions of (i), with text starting with "-". These one-hyphen strings can be further split into texts that start with 2 hyphens, etc.. up to 6 hyphens.

    I would like to get the descriptions so that the text is the full text description, starting from (i), and concatenating strings up to the most detailed level.
    For example, the description for code "0101 19 10" would become "Live horses, asses, mules and hinnies; Horses; Other; For slaughter".

    If you encounter a higher-level hierarchy, it should retrace the hierarchy and construct the proper description. Eg. for code "0101 19 90" , it would become "Live horses, asses, mules and hinnies; Horses; Other; Other".

    Is there a way to construct this in Stata?
    Thank you everyone,
    Glenn
    Attached Files
Working...
X