Announcement

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

  • Creating a %15.0f variable

    My dataset structure is as follow:

    Code:
    uf    mun    dist    subdist    set
    11    15    5    0    1
    11    15    5    0    1
    11    15    5    0    1
    11    15    5    0    1
    11    15    5    0    1
    11    15    5    0    1
    11    15    5    0    1
    11    15    5    0    1
    11    15    5    0    1
    11    15    5    0    1
    My row identifier should be a 15 digit one which I should get through the code below:
    Code:
    gen double setor = 100000000000000*uf + 1000000000000*mun + 10000000*dist + 100000*subdist + 1000*set
    format setor %15.0f
    However, Stata gives me back the variable below, which is not displayed as %15.0f. How could I get it right?

    Code:
    setor
    1.11500005e+15
    1.11500005e+15
    1.11500005e+15
    1.11500005e+15
    1.11500005e+15
    1.11500005e+15
    1.11500005e+15
    1.11500005e+15
    1.11500005e+15
    1.11500005e+15

  • #2
    You're miscounting somewhere. The created values have 16 digits, so Stata is ignoring the specified format. You just need another. Note that a format too large is not usually a problem, but a format too small often is.

    As your example is just repeating the same calculation 10 times, I slimmed it down.

    Code:
    . clear 
    
    . input uf    mun    dist    subdist    set
    
                uf        mun       dist    subdist        set
      1. 11    15    5    0    1
     2. end 
    
    . gen double setor = 100000000000000*uf + 1000000000000*mun + 10000000*dist + 100000*subdist + 1000*set
    
    . format setor %15.0f
    
    . list 
    
         +--------------------------------------------------+
         | uf   mun   dist   subdist   set            setor |
         |--------------------------------------------------|
      1. | 11    15      5         0     1   1.11500005e+15 |
         +--------------------------------------------------+
    
    . format %23.0f setor
    
    . l
    
         +----------------------------------------------------+
         | uf   mun   dist   subdist   set              setor |
         |----------------------------------------------------|
      1. | 11    15      5         0     1   1115000050001000 |
         +----------------------------------------------------+

    Comment


    • #3
      When you multiply uf = 11 by the first large number, you are already making a 16 digit number. If you try it with format %16.0f, it displays as an integer:

      Code:
      . format setor %16.0f
      
      . list setor
      
           +------------------+
           |            setor |
           |------------------|
        1. | 1115000050001000 |
        2. | 1115000050001000 |
        3. | 1115000050001000 |
        4. | 1115000050001000 |
        5. | 1115000050001000 |
           |------------------|
        6. | 1115000050001000 |
        7. | 1115000050001000 |
        8. | 1115000050001000 |
        9. | 1115000050001000 |
       10. | 1115000050001000 |
           +------------------+
      That said, unless you are going to use this "identifier" for calculations, given its length, you might be better off making it a string variable. See -egen, concat()- for how to put together a string out of those variables.

      Comment


      • #4
        I agree with Clyde's suggestion to consider string identifiers. Note also that from the outset (STB-50, 1999) egen, concat() was explicitly written to allow different punctuation, including spaces or commas or whatever. That would make it especially easily to take apart again, as often seems needed.

        Comment

        Working...
        X