Announcement

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

  • Generating dummy

    Dear Community,

    I am trying to generate a dummy for current Y and N values.
    My code looks like this:
    gen CGCPO09Vbyte = .
    replace CGCPO09Vbyte = 1 if CGCPO09V == "Y"
    replace CGCPO09Vbyte = 0 if CGCPO09V == "N"

    However, Stata makes no changes when I use this command:
    . gen CGCPO09Vbyte = .
    (11,894 missing values generated)

    . replace CGCPO09Vbyte = 1 if CGCPO09V == "Y"
    (0 real changes made)

    . replace CGCPO09Vbyte = 0 if CGCPO09V == "N"
    (0 real changes made)

    It does not recognize the Y and N, and I do not know how to solve this.

    The variable list looks like this:
    Click image for larger version

Name:	Stata.png
Views:	1
Size:	8.0 KB
ID:	1714240


    Please let me know what I am doing wrong, thank you in advance
    Last edited by Tim Huizingh; 19 May 2023, 12:19.

  • #2
    Full real name please. See https://www.statalist.org/forums/help#realnames and https://www.statalist.org/forums/help#adviceextras #3

    More important: No data example here, just an image, contrary to advice at https://www.statalist.org/forums/help#stata

    My best guess is that you have multiple spaces there as well as characters Y and N, so try

    Code:
    replace CGCPO09V = trim(CGCPO09V)
    and then try again. If no change, we need to know more about your data. Please read about dataex at the last link above.

    Comment


    • #3
      Thank you so much! The spaces were indeed the problem. Everything works fine now.
      I have sent a message to the site moderators, asking them to change my username to my real full name

      Comment


      • #4
        Good!

        Comment

        Working...
        X