Announcement

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

  • #16
    -gen variable = l0.variable- is not what you ran. If variable already exists, you can't -gen- it. If it doesn't exist, Stata will complain about your using it on the right hand side. It's really important to show exactly what you did. I'm guessing you did something like this:

    Code:
    gen lrainfall = l1.rainfall
    and got 614 missing cases. Remember that since 2008 is your first year, there will be no lagged value for any observation with year == 2008. So you will have missing values whenever year == 2008. Since you have a total of 1842 observations, according to your data ex, 614 is exactly one third of that, and so it is exactly what I would expect. This version will give you the correct lagged values. Go with it.

    If you did
    Code:
    gen lrainfall = l0.rainfall
    then lrainfall will be not just "hardly different" from the real values, they will be exactly equal to the original values. l0 means a 0-order lag, i.e. no lag at all: the current value. So this clearly is of no real use here.

    Comment


    • #17
      Thanks very much Clyde
      I actually tried the both commands. Sorry I used "variable" to make it general.

      USING
      gen lrainfall = l1.rainfall, how do I proceed with the missing values as this will reduce my sample size despite giving me the correct lagged values.
      Is it possible I get lagged values for year 2008?

      Comment


      • #18
        [quotehow do I proceed with the missing values as this will reduce my sample size despite giving me the correct lagged values.
        Is it possible I get lagged values for year 2008?[/quote]
        Unless you can find additional data for some year before 2008, there is no way to get lagged values for 2008. Lagged means from the preceding period. It is always undefined (missing) in the first period.

        Just proceed with your analysis as planned. Stata will automatically exclude the 2008 observations because they have missing values for the variables involved. Yes, that will decrease your sample size, but there is nothing you can do about that. If your sample size is inadequate, the only solution is to get more data.

        Comment


        • #19
          Dear Clyde,

          Could you please help me to fix my problem. I have a long data of longitudinal study of 30 patients. I have a variable "time" from 1 to 6 (6 repeated observations/patients) and a variable "dose" for each time. My outcome is IgG and I want to know whether dose has effects on IgG or not. The problem is that the dose of time 1 will have effect on dose of time 2. I use - xtmixed - but I don't know how to creat a lag variable of dose in this case.

          Please help me to do it

          Thank you so much

          Comment


          • #20
            In general, you should show an example of your data when asking for help with code. Nevertheless, based on the general outline you describe, it will be something like this:

            Code:
            xtset patient_id time
            mixed igg dose L1.dose || patient_id: // & PERHAPS OTHER VARIABLES
            Notes:

            1. Replace patient_id by whatever variable you have that identifies individual patients.
            2. If you are using Stata version 13 or later, -xtmixed- has been renamed -mixed-.
            3. In the code L1.dose is the lagged dose variable, lagged by one time period. Read -help tsvarlist-.

            In the future, when asking for help with code, show data examples, and use the -dataex- command to do so. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

            When asking for help with code, always show example data. When showing example data, always use -dataex-.

            .
            It is not wise to address your post to any particular person. The Forum has a large membership with varying expertise. There may be somebody better suited to answer your question than the one you choose. Moreover, the person you address it to may simply not be on the Forum that day, or might not be interested in it. Yet the mention of that person's name may discourage others from answering it. So you only reduce your chances of getting the best, most timely answer when you address your question to a particular person.


            Comment


            • #21
              Thank you so much, Clyde

              I will follow your instructions when I use the forum. Sorry for the inconvenience I have made.

              I will try you suggested codes.

              Best regards

              Anh

              Comment


              • #22
                There is going to be missing values for the first observation in each gnno because there is no lag for the first observation. Try this and see what I am talking about.

                tsset qnno year
                gen order = _n
                tsset qnno order
                gen L1rainfall = L1.rainfall

                Comment


                • #23
                  Dear Statalist
                  I am working with panel data, where data is observed over 3 waves. I am trying to conduct prospective analysis on one of the variables that is only observed in 2 waves. For example: how a change in BMI can be predicted by a change in income in the previous period controlling for BMI in the previous period. (ie. BMI_t= a+bBMI_t-1+ dM_t-1). However, when using the lagged term lagBMI=BMI[_n-], my regression omitts all terms due to collinearity. Any help would be much appreciated.

                  Comment

                  Working...
                  X