Announcement

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

  • Help with the moss command

    Hello, I need to separate this database into columns, one column with the string variable and three columns with numeric variables. I'm trying to do it for the "moss", but I'm not succeeding. Can you help me?

    AC MANCIO LIMA 1200336 0,000245682292 414.497,55
    AC MARECHAL THAUMATURGO 1200351 0,000198480153 334.861,48
    AC PORTO WALTER 1200393 0,000135417294 228.466,35
    AC RIO BRANCO 1200401 0,001761485653 2.971.852,28


    COLUMN 1 | COLUMN 2 | COLUMN 3 | COLUMN 4
    AC MANCIO LIMA | 1200336 | 0,000245682292 | 414.497,55
    AC MARECHAL THAUMATURGO | 1200351 | 0,000198480153 | 334.861,48
    AC PORTO WALTER | 1200393 | 0,000135417294 | 228.466,35
    AC RIO BRANCO | 1200401 | 0,001761485653 | 2.971.852,28

    Thank you so much!
    Maria Laura

  • #2
    moss is from SSC.

    Here's one way to do it. Please note the use of the dataex command.

    https://www.statalist.org/forums/help#stata explains.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str57 whatever
    "AC MANCIO LIMA 1200336 0,000245682292 414.497,55"         
    "AC MARECHAL THAUMATURGO 1200351 0,000198480153 334.861,48"
    "AC PORTO WALTER 1200393 0,000135417294 228.466,35"        
    "AC RIO BRANCO 1200401 0,001761485653 2.971.852,28"        
    end
    
    * position of first number 
    gen pos = 100 
    
    forval j = 0/9 {
        replace pos = min(strpos(whatever, "`j'") - 1, pos) if strpos(whatever, "`j'")
    }
    
    gen wanted1 = trim(substr(whatever, 1, pos))
    
    replace whatever = subinstr(whatever, wanted1, "", 1)
    
    split whatever 
    
    destring whatever?, replace dpcomma ignore(".")
    
    rename (whatever?) (wanted2 wanted3 wanted4)
    
    list wanted? 
    
         +-----------------------------------------------------------+
         |                 wanted1   wanted2     wanted3     wanted4 |
         |-----------------------------------------------------------|
      1. |          AC MANCIO LIMA   1200336   .00024568   414497.55 |
      2. | AC MARECHAL THAUMATURGO   1200351   .00019848   334861.48 |
      3. |         AC PORTO WALTER   1200393   .00013542   228466.35 |
      4. |           AC RIO BRANCO   1200401   .00176149   2971852.3 |
         +-----------------------------------------------------------+

    Comment


    • #3
      Thank you very much Nick, it solved my problem!

      Comment

      Working...
      X