Announcement

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

  • Error when writing data

    Hi everyone. I'm trying to create a new file based on the data in my .dta file. I'm trying to create a full list of numbers based on starting and ending points in all the rows. Stata is showing invalid syntax error. Could anyone please help me point out the error in this?

    The sample of the base file is:

    sic_start sic_end
    100 199
    200 299
    700 799
    910 919
    2048 2048


    Code:
    capture confirm file ffsic.dta
    if !_rc erase ffsic.dta
    tempname ffsic
    
    postfile `ffsic' siccode using ffsic.dta
    
    forvalues j=1/`=_N' {
    
    forvalues k=sic_start[`j']/sic_end[`j'] {
    post `ffsic' (`k')
    }
    }
    
    postclose `ffsic'

  • #2
    The construct -forvalues i = #/# {...}- requires that the #'s be numbers, not expressions that evaluate as numbers at run-time. So to do what you are trying to do requires a small modification of your code:
    Code:
    forvalues k= `=sic_start[`j']'/`=sic_end[`j']' {
        post `ffsic' (`k')
    }
    Last edited by Clyde Schechter; 14 Apr 2023, 11:29.

    Comment

    Working...
    X