Announcement

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

  • Concatenate variables from csv file dynamically

    Hello,

    I have a complexe task to do, here a csv file:
    Code:
    C1,C1,C3,A,D1,D2,D3
    ME,PATRICE,PARIS,0,1,122,145
    YOU,JEAN,ROME,7,1,745,111
    Note that you can have more than 3 columns before A, and more than 3 columns after XA

    I need to build a variable with concatenation of C1, C2, C3 columns (again you can have between 1 and x columns)

    Something like this:
    Code:
    gen final=C1 + "." + C2 + "." + C3
    Code:
    ME.PATRICE.PARIS
    YOU.JEAN.ROME
    Note also that when executin this, I can already have other variables in memory.

    How can I do this ?

  • #2
    This is difficult to follow, but in Stata, you identify variables by their names. If you can import two files that differ (or make them up), use the dataex command to show us how the variables are arranged in separate instances, then someone can suggest a way to handle this. This entails, e.g., copying and pasting the results of

    Code:
    qui ds
    dataex `=word("`r(varlist)'", 1)' - `=word("`r(varlist)'", 7)' in 1/5

    Comment


    • #3
      A thought.

      Since all C are strings, then adding them all is just going to result in some ".." when a C is blank. You can clean that up in a second step with subinstr.

      Comment

      Working...
      X