Announcement

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

  • loop by avoiding certain values

    Hi guys:
    i have a question about loop in stata. the version i use is stata 16. below is my code. Basically, i try to prevent a scenario in which x=y. how to write this code? i got the
    Code:
    if `x' == `y' {
                drop `x'
    by asking newbing. but obvisouly, it does not work... Thanks in advance!
    Code:
    foreach y of numlist 40 41 42 51 52 53 54 55 56 57 58 60 70 80 90 91 92 93 94 95 100 101 110 115 130 135 140 145 150 155 160 165 200 205 210 211 212 220 221 223 225 230 232 235 240 245 255 260 265 267 269 271 273 275 280 290 300 305 310 315 316 317 325 327 329 331 332 335 337 338 339 341 343 344 345 346 347 349 350 352 355 359 360 365 366 367 368 369 370 371 372 373 375 380 385 390 395 402 403 404 411 420 432 433 434 435 436 437 438 439 450 451 452 461 471 475 481 482 483 484 490 500 501 510 511 516 517 520 522 530 531 540 541 551 552 553 560 565 570 571 572 580 581 590 591 600 615 616 620 625 626 630 640 645 651 652 660 663 666 670 678 679 680 690 692 694 696 698 700 701 702 703 704 705 710 712 713 730 731 732 740 750 760 770 771 775 780 781 790 800 811 812 816 817 820 830 835 840 850 860 900 910 920 935 940 946 947 950 955 970 983 986 987 990 {
        foreach x of numlist 2 20 31 40 41 42 51 52 53 54 55 56 57 58 60 70 80 90 91 92 93 94 95 100 101 110 115 130 135 140 145 150 155 160 165 200 205 210 211 212 220 221 223 225 230 232 235 240 245 255 260 265 267 269 271 273 275 280 290 300 305 310 315 316 317 325 327 329 331 332 335 337 338 339 341 343 344 345 346 347 349 350 352 355 359 360 365 366 367 368 369 370 371 372 373 375 380 385 390 395 402 403 404 411 420 432 433 434 435 436 437 438 439 450 451 452 461 471 475 481 482 483 484 490 500 501 510 511 516 517 520 522 530 531 540 541 551 552 553 560 565 570 571 572 580 581 590 591 600 615 616 620 625 626 630 640 645 651 652 660 663 666 670 678 679 680 690 692 694 696 698 700 701 702 703 704 705 710 712 713 730 731 732 740 750 760 770 771 775 780 781 790 800 811 812 816 817 820 830 835 840 850 860 900 910 920 935 940 946 947 950 955 970 983 986 987 990 {
    if `x' == `y' {
                drop `x'
    clear
    use state`x'
    rename ccode ccode2
    sort year
    save statee`x', replace
    clear
    use state`y'
    merge year using "statee`x'"
    drop if ccode2==.
    drop _merge
    save state`y'_`x', replace
    clear
    append using state`y'_2 state`y'_20
    save state`y'_ddy, replace
    clear
    append using state`y'_ddy state`y'_`z'
    drop if ccode==ccode2
    save state`y'_ddy, replace
         }
       }
    }

  • #2
    Your syntax is illegal. You can't drop variable names that're numbers as you can't have variable names that're numbers.

    Edit: And why all this looping? What's the real goal here, just at append stuff?

    Comment


    • #3
      Originally posted by Jared Greathouse View Post
      Your syntax is illegal. You can't drop variable names that're numbers as you can't have variable names that're numbers.

      Edit: And why all this looping? What's the real goal here, just at append stuff?
      Thanks. your answer makes sense. To you question, i was trying to create a directed dyad year dataset. those numbers are country codes.

      Comment


      • #4
        Alright well, can you give two dataexs which illustrate this problem?

        Comment

        Working...
        X