Announcement

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

  • add missing values

    hi, i would like to add missing values to adding the mean.
    The missing values are mostly between 2012-2015,
    my dataset is from 2002-2015, so the last 3 years are missing


    i tried this:
    bysort country year: egen var_all = mean(var)

    but the missing values are not added :/

    then i tried this:


    replace var_all = (var_all[_n-1]+var_all[_n+1])/2 if var_all == .


  • #2
    "add missing values" here might mean, so far as I can see

    1. What it says: add missing values in the data to each other, or to something else. Stata's idea is to ignore missing values when adding up.

    2. Insert observations with missing values into the dataset.

    3. Replace missing values with some mean. This seems likeliest, but your code veers between calculating a group mean and interpolating between values on either side.

    4. Something else.

    If you have annual data, then

    Code:
    bysort country year: egen var_all = mean(var)
    will be taking means of single values, and so just produce a copy of the variable being averaged.

    Please give us a data example (https://www.statalist.org/forums/help#stata) showing a sample of your data and what you would like the data to be.

    Comment


    • #3
      Data will look this:
      Click image for larger version

Name:	Zwischenablage02.jpg
Views:	1
Size:	134.8 KB
ID:	1407140

      Comment


      • #4
        as you can see new generatet variable corr_all and v2x_corr_all are not filling the missin gdata e.g. albania 2013-2015

        Comment


        • #5
          You're not paying attention to what we ask. In #2 I linked to the Stata FAQ Advice. In replying you give a screenshot and you don't give the code you used. Sorry, but I understand nothing about what you tried.

          This isn't a help line in which there are people who have to answer your questions. It's a forum in which people may give good answers if they see good questions that can be answered.

          Comment


          • #6
            sorry, its a bit hard for me as i stata newbie also my english is not so good :/.

            i think i already insert the missing values, for example alblania 2013-2015 as .
            now i want to let stata insert a mean value for this missing data, and the mean should be generated by the given values. for albania e.g. is from 2008-2012 always the same value. i know that is not so clean to put a mean value there. but maybe you have an idea, to fill in the last 3 years (mostly cases its nearby the same value)

            Comment

            Working...
            X