Announcement

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

  • type mismatch double and str18

    Hey,
    I have a type mismatch Problem with the variable Bevölkerungswachstum_2007 which is str18 and the variable Bevölkerungswachstum_2006 which is double, since I want to generate a variable which combines values out of both variables I Need to know which Format Bevölkerungswachstum_Projektjahr Needs.
    Code:
    generate double Bevölkerungswachstum_Projektjahr = .
    replace Bevölkerungswachstum_Projektjahr = Bevölkerungswachstum_2005 if date_Ideenwettbewerb == 2005
    replace Bevölkerungswachstum_Projektjahr = Bevölkerungswachstum_2005 if inrange((Projektbeginn), mdy(01, 01, 2005), mdy(12, 31, 2005))
    replace Bevölkerungswachstum_Projektjahr = Bevölkerungswachstum_2006 if date_Ideenwettbewerb == 2006
    replace Bevölkerungswachstum_Projektjahr = Bevölkerungswachstum_2006 if inrange((Projektbeginn), mdy(01, 01, 2006), mdy(12, 31, 2006))
    replace Bevölkerungswachstum_Projektjahr = Bevölkerungswachstum_2007 if date_Ideenwettbewerb == 2007
    replace Bevölkerungswachstum_Projektjahr = Bevölkerungswachstum_2007 if inrange((Projektbeginn), mdy(01, 01, 2007), mdy(12, 31, 2007))
    If you Need further Information do not hesitate to ask!
    Thanks

  • #2
    It seems that

    Code:
    Bevölkerungswachstum_2007
    is str18 but similar variables are double. You could try destring (you may need to use its format() option) but there may be an underlying problem which explains why that variable is different.

    Comment


    • #3
      Jay, function year() will extract the year from a date variable.
      Code:
      clear
      
      input str20 pb
      "30/03/2005"
      "13/12/2007"
      "01/01/2006"
      end
      
      generate d=date(pb,"DMY")
      format d %td
      gen yr=year(d)
      replace Bevölkerungswachstum_Projektjahr = Bevölkerungswachstum_2007 if inrange((Projektbeginn), mdy(01, 01, 2007), mdy(12, 31, 2007))
      is equivalently
      replace Bevölkerungswachstum_Projektjahr = Bevölkerungswachstum_2007 if year(Projektbeginn)==2007

      If you have a bunch of these statements, consider merge-ing with a reference file. Updating for next year will be much easier.
      Nick's explanation of the error you are getting is correct.
      Best, Sergiy Radyakin

      Comment


      • #4
        Code:
        destring
        worked absolutely fine, the underlying problem was that some missing Variables where coded as
        Code:
        ..

        Comment

        Working...
        X