Announcement

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

  • reshaping missing variables

    Hello,

    I'm trying to create a dataset with years ranging from 1975 to 2018. However one of the variables (famid) i'm using only exists after 1984. I then used famid to create another variable (primeagefam). I created the variable and tried to make it missing for years before 1984 but STATA is giving me an error message when i tried reshaping the data (i'm guessing you can't reshape missing values in stata?) My end goal is to have primagefam as one of my columns and all the years before 1984 to be missing (i have other columns as well but all of them have data for all the years starting from 1974). Can you please tell me how i can do this?

    Here is part of my code (line 41 and 46 is were i tried to create the missing variables)
    Click image for larger version

Name:	code sample.PNG
Views:	1
Size:	86.4 KB
ID:	1496536


  • #2
    i'm guessing you can't reshape missing values in stata?
    Bad guess, Stata allows you to reshape missing values.

    In any event, it's not clear to me how primeagefam will have any bearing on the problem, since your gcollapse command does not include primeagefam, so I do not expect it to appear in the dataset that is being reshaped. But I could be wrong, I'm just guessing about what is happening.

    STATA is giving me an error message when i tried reshaping the data
    Perhaps you could share the error message from Stata with us? They are often very informative and helpful in figuring out what went wrong.

    To improve the likelihood Statalist members can help you, please take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. It's particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using code delimiters [CODE] and [/CODE], and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

    The more you help others understand your problem, the more likely others are to be able to help you solve your problem.


    Comment


    • #3
      Oh i do collapse using primeage fam in another part of my code. Also here is the error stata gives me.

      Click image for larger version

Name:	abifioa.PNG
Views:	1
Size:	16.8 KB
ID:	1496540

      Click image for larger version

Name:	error.PNG
Views:	1
Size:	19.2 KB
ID:	1496541

      Comment


      • #4
        You can have missing values in the variables you are reshaping, like lfpr_prime.

        But you cannot use a missing value as part of the name of a variable that's been reshaped. That is what you are trying to do, rather than

        reshape missing values
        You have primeagefam = 0 or 1 in 1984 and later, so your wide variable names will become
        Code:
        lfpr_prime0
        lfpr_prime1
        if you only reshaped data from 1984 and later. But you cannot have a variable named
        Code:
        lfpr_prime.
        for years before 1984 - that is not a legal Stata varaible name.

        After your collapse, do something like
        Code:
        replace primeagefam = 9 if primeagefam==.
        and you can then reshape, creating lfpr_prime9 along with the other two variables.

        In post #1 you wrote

        My end goal is to have primagefam as one of my columns and all the years before 1984 to be missing
        but that is not at all what using j(primeagefam) causes to happen, so I am not sure this is going to do what you expect.

        Comment

        Working...
        X