Announcement

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

  • Recognizing Texts Observations

    Dear All,

    I have an issue with making STATA to recognize txt observations.

    I have a table that looks like the below one and I am required to generate the column Same if the person have similar choice under column mobile and laptop.

    PersonID Mobile Laptop Same
    4896 Apple Apple 1
    5163 Apple Dell 0
    I used the following commands:

    gen Same=.

    . replace Same==1 if( Mobile == Laptop)


    But STATA reported the below error:

    == invalid name


    Any advices? your help will be so appreciated

    Regards,

    Mohammed Khaled

  • #2
    Code:
    replace Same = 1 if Mobile == Laptop

    Comment


    • #3
      Thanks Øyvind Snilsberg !!

      Comment


      • #4
        Dear All,

        I followed the following codes:


        encode Mobile, gen(Mobile2)
        encode Laptop, gen(Laptop2)
        gen Same=.
        replace Same = 1 if ( Mobile2 == Laptop2 )
        replace Same = 0 if ( Same== . )



        It worked well and then I realized that some data are missing and I had to extract the data again and repeat the steps but it's not working anymore, can anyone tell me what might went wrong?

        Your assistance will be so appreciated


        Comment


        • #5
          at what step did it stop working and what error message did Stata give?

          Comment


          • #6
            It gave me "Invalid name"

            But I figured out that I needed to trim the data for extra spaces and then it worked.

            Thanks Øyvind Snilsberg for your support and following up with me, it's truly appreciated.

            Comment

            Working...
            X