Announcement

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

  • #16
    post_se and pre_se can only occur once for each pid because the data was selected on one time self-employment. The number I want to find is the average wage growth starting from the year before until the year after slef-employment. The formula I wanted to use is (mean(post_se_pay)-mean(pre_se_pay)/number of years between pre_se and post_se. Now I dont really know how I can get this average number of years. This is what I thought: by pid (wave), sort: egen years_between = wave(post_se)-wave(pre_se) but that obviously doesnt work and I dont know how to account for the cases when there is no pre_se for example. I am really sorry to depend on you all the time but I dont find any information regarding my problem anywhere...

    Comment


    • #17
      Well, you can calculate the number of waves between pre_se and post_se with
      Code:
      foreach v of varlist pre_se post_se {
          egen wave_`v' = max(cond(`v', wave, .))
      }
      
      gen waves_between = wave_post_se - wave_pre_se
      And if waves were administered annually, then this is also the number of years between. If waves came every W years regularly, then just multiplying that result by W gives you years between. If the waves came at irregular intervals, then perhaps you can go back to the original source of this survey data and you will likely find that there is a variable that contains the date of administration.

      All of that said, it seems that your major problem here is conceptual, not code. You have not yet figured out what measure(s) to use to operationalize the construct you are trying to study. And you seem to just now be realizing that you cannot do a pre-post comparison for entities that have no pre- data (nor for entities that lack post- data.) So I think rather than continuing to throw code at this data, you would be better off sitting down with your coach, and perhaps others who have expertise in your area, and brainstorming how to approach your research goal. You may end up finding ways to use the data you have, or you may need to supplement it with other sources, or perhaps even discard it and use something else. But I think you need to resolve your conceptual plan before you do anything else. And I can't help you do that; this is totally out of my area of expertise.

      Comment


      • #18
        Hello Clyde, indeed you are right that I did not think it over thoughtfully but I assumed that the code my coach gave me was right. However, and thankfully to your support, I am on the right way and nearly there. I want to clarify that I need the number of waves between pre_se and post_se for every pid separately. Maybe your code was right but the first part gave me an error: program error: code follows on the same line as open brace... I ran the second line alone but then I just get a 1 everywhere...

        Comment


        • #19
          So, yes, the code I wrote did not get the number of intervening waves by person, but rather overall, which is clearly not useful. It should be

          Code:
          foreach v of varlist pre_se post_se {
              egen wave_`v' = max(cond(`v', wave, .)), by(pid)
          }
          gen waves_between = wave_post_se - wave_pre_se
          I cannot explain why you got that "code follows on same line as open brace" error. Clearly that is not true. Perhaps something got corrupted when you copied the code into Stata. Do make sure to select the entire block of code and copy it as a whole, so as to assure that line breaks and indentation are preserved.

          You cannot run the second line of this code separately from the first. The whole block must be run in one action so that the local macro v which is created by the -foreach- command remains in scope when the -egen- command references it. If you try to run them separately, `v' will not find a local macro v to match and you will get a syntax error.

          Comment

          Working...
          X