Announcement

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

  • no space for concat

    Hi,
    I want to connate the following variable of the dataset,

    the outcome is not what I want to to get
    . I want
    really only one space between numbers
    , but there is
    wide space
    . How can
    move out the spacing

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -
    dataex-. To install: 
    ssc install 
    dataex
    clear
    input str1(dev_active_proj_sm_1 dev_active_proj_sm_2 dev_active_proj_sm_3 dev_active_proj_sm_4 dev_active_proj_sm_5)
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  "3" "" "" 
    "1" ""  ""  "" "" 
    "1" ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    "1" ""  ""  "" "" 
    "1" ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  "2" ""  "" "" 
    ""  "2" ""  "" "" 
    "1" ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    "1" ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    "1" ""  ""  "" "" 
    ""  ""  ""  "" "" 
    "1" ""  ""  "" "5"
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  ""  "" "" 
    "1" ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  ""  "" "" 
    "1" ""  ""  "" "" 
    ""  "2" ""  "" "" 
    "1" ""  ""  "" "" 
    "1" ""  ""  "" "" 
    ""  ""  ""  "" "" 
    "1" "2" ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  "3" "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    "1" ""  ""  "" "" 
    "1" ""  ""  "" "" 
    ""  ""  ""  "" "" 
    "1" ""  ""  "" "" 
    "1" ""  ""  "" "" 
    "1" ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  "3" "" "" 
    ""  ""  ""  "" "" 
    ""  "2" ""  "" "" 
    ""  "2" ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    ""  ""  ""  "" "" 
    "1" ""  ""  "" "" 
    end
    ------------------ copy up to and including the previous line ------------------

    Listed 100 out of 1298 observations
    Use the count
    (
    ) option to list more


    Mycode
    ,

    egen
    concat_var
    =concat
    (dev_active_proj_sm_0-dev_active_proj_sm_5),
    p
    (" ")
    The out put like that follow,
    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -
    dataex-. To install: 
    ssc install 
    dataex
    clear
    input str9 
    concat_var
    "0"     
    "0"     
    "0"     
    "2"     
    "0"     
    "3"     
    "1"     
    "1"     
    "0"     
    "0"     
    "0"     
    "1"     
    "1"     
    ""      
    "0"     
    "2"     
    "0"     
    "0"     
    "2"     
    "2"     
    "2"     
    "1"     
    ""      
    "0"     
    "0"     
    "0"     
    "0"     
    "0"     
    "2"     
    "0"     
    "0"     
    "2"     
    "2"     
    "0"     
    "0"     
    "0"     
    "0"     
    "1"     
    "2"     
    "2"     
    "0"     
    "0"     
    "0"     
    "1"     
    "0"     
    "1    5"
    "0"     
    "0"     
    "0"     
    "0"     
    "0"     
    "0"     
    "2"     
    "0"     
    "0"     
    "2"     
    "0"     
    "0"     
    "0"     
    "0"     
    "0"     
    "0"     
    "2"     
    "0"     
    "1"     
    "2"     
    "0"     
    "1"     
    "2"     
    "1"     
    "1"     
    "0"     
    "1 2"   
    "2"     
    "0"     
    "2"     
    "0"     
    "2"     
    "3"     
    "0"     
    "0"     
    "1"     
    "1"     
    "0"     
    "1"     
    "1"     
    "1"     
    "0"     
    "0"     
    "0"     
    "3"     
    "0"     
    "2"     
    "2"     
    "0"     
    "0"     
    "0"     
    "0"     
    "0"     
    "1"     
    end
    ------------------ copy up to and including the previous line ------------------

    You will see about the output : "1 5", there is more than one space between these two number, I really want only one space "1 5"
    please guide me how to proceed to get that way

  • #2
    You may want to read about the function stritrim.
    Best regards,

    Marcos

    Comment


    • #3
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str1(dev_active_proj_sm_1 dev_active_proj_sm_2 dev_active_proj_sm_3 dev_active_proj_sm_4 dev_active_proj_sm_5)
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  "3" "" "" 
      "1" ""  ""  "" "" 
      "1" ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      "1" ""  ""  "" "" 
      "1" ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  "2" ""  "" "" 
      ""  "2" ""  "" "" 
      "1" ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      "1" ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      "1" ""  ""  "" "" 
      ""  ""  ""  "" "" 
      "1" ""  ""  "" "5"
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  ""  "" "" 
      "1" ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  ""  "" "" 
      "1" ""  ""  "" "" 
      ""  "2" ""  "" "" 
      "1" ""  ""  "" "" 
      "1" ""  ""  "" "" 
      ""  ""  ""  "" "" 
      "1" "2" ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  "3" "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      "1" ""  ""  "" "" 
      "1" ""  ""  "" "" 
      ""  ""  ""  "" "" 
      "1" ""  ""  "" "" 
      "1" ""  ""  "" "" 
      "1" ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  "3" "" "" 
      ""  ""  ""  "" "" 
      ""  "2" ""  "" "" 
      ""  "2" ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      ""  ""  ""  "" "" 
      "1" ""  ""  "" "" 
      end
      
      egen wanted = concat(dev_active_proj_sm_?)
      
      tab wanted 
      
           wanted |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                1 |         17       40.48       40.48
               12 |          1        2.38       42.86
               15 |          1        2.38       45.24
                2 |         20       47.62       92.86
                3 |          3        7.14      100.00
      ------------+-----------------------------------
            Total |         42      100.00
      From the help for egen

      By default, variables are added end to end: punct(pchars) may be used to specify punctuation, such as a space, punct(" "), or a comma, punct(,).
      So you don't need to do anything about the punct() option.

      Comment


      • #4

        Greak thanks
        ,
        That is what
        i really want !

        Comment

        Working...
        X