Announcement

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

  • Problem in creating new varibles

    Hi, i'm new to stata and i want to ask for some advices. I have the data as follow:
    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	8.6 KB
ID:	1450818

    Now I want to create a new variable "person" as a combination of tinh, huyen, xa, hoso, matv which for example would be: "person = 1011331"
    Could someone show me the way to create such a value? Since my data has over 100,000 observations.
    Thank you.

  • #2
    Annie:
    you may want to try:
    Code:
    egen new=concat(tinh huyen xa hoso matv)
    As this code will report a -string- variable, if you want to turn into a numeric one, try:
    Code:
    destring new, gen(num_new)
    The following toy-example works all this stuff out:
    Code:
    . use "C:\Program Files (x86)\Stata15\ado\base\a\auto.dta"
    (1978 Automobile Data)
    
    . egen new=concat(price mpg)
    
    . destring new, g(num_new)
    new: all characters numeric; num_new generated as long
    
    . list new num_new in 1/10
    
         +-------------------+
         |     new   num_new |
         |-------------------|
      1. |  409922    409922 |
      2. |  474917    474917 |
      3. |  379922    379922 |
      4. |  481620    481620 |
      5. |  782715    782715 |
         |-------------------|
      6. |  578818    578818 |
      7. |  445326    445326 |
      8. |  518920    518920 |
      9. | 1037216   1037216 |
     10. |  408219    408219 |
         +-------------------
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment

    Working...
    X