Announcement

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

  • How to use Egen variable as a value in Panel data

    Hi Stata Community,


    I have a Panel data ( with xtset format) and I have created egen variable to estimate the mean of the CPI for each country over the period of 2021-2022 (monthly data ) as follows ;


    egen avrInf = mean(CPI) if tin(2020m1,2022m12), by(code)


    When I try to identify the list of countries that had CPI in 2023 above the calculated Egen ( 2021-2022) , the program display no results , as per the below ;


    # This will not show any results (

    list country CPI time if tin(2023m1,) & CPI > avrInf


    # This will show the results for 2022 only ( and will ignore 2023)


    list country CPI time if tin(2022m1,) & CPI > avrInf


    Grateful for your support and any help .
    B


  • #2
    Indeed. Your if qualifier excluded any months but those specified from the calculation. What you want is more nearly

    Code:
    egen avrInf = mean(cond(tin(2020m1,2022m12), CPI, .)), by(code)
    as explained (e.g.) in Section 9 of https://journals.sagepub.com/doi/pdf...867X1101100210

    Comment


    • #3
      Great ! Many thanks . Works now .

      Comment

      Working...
      X