Announcement

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

  • Creating new variables using the subset of an existing variable

    Hello,

    I am pretty new user of Stata. I would like to create new variables by using the subset of an existing variable. I have the values of the first 5 columns of the table stated below. I want to create the last three columns.
    Analyst A released her forecasts for EPS1, EPS2, and EPS3 on March 2014. We can see these values at the fifth column. I would like to create the last three new columns by matching the name of analyst from the first column and also check Date of forecasting and forecast date. It seems a bit confusing for me.

    Thanks in advance for your help.

    Volkan
    Analyst FPI Forecast Date Date of forecasting Forecasted Value (EPS) EPS1 (forecast for year 1 end) EPS2 (forecast for year 2 end) EPS3 (forecast for year 3 end)
    A 1 2014 December March 2014 1.73 (it is EPS1 since FPI=1) 1.73 1.89 2.25
    A 2 2015 December March 2014 1.89 (EPS2 it is EPS2 since FPI=2)
    A 3 2016 December March 2014 2.25 (EPS3)
    B 1 2014 December April
    2014
    1.85 1.85

  • #2
    Code:
    sort Analyst FPI 
    forval j = 1/3 { 
          by Analyst : gen EPS`j' = EPS[`j'] 
    }

    Comment


    • #3
      Thanks Nick. It works. Can I add more criteria into 'sort' function? For example if analyst has also forecasts for different companies


      Analyst FPI Company Forecast Date Date of forecasting Forecasted Value (EPS) EPS1 (forecast for year 1 end) EPS2 (forecast for year 2 end) EPS3 (forecast for year 3 end)
      A 1 Apple 2014 December March 2014 1.73 (it is EPS1 since FPI=1) 1.73 1.89 2.25
      A 2 Apple 2015 December March 2014 1.89 (EPS2 it is EPS2 since FPI=2) 1.73 1.89 2.25
      A 3 Apple 2016 December March 2014 2.25 (EPS3) 1.73 1.89 2.25
      A 1 Orange 2014 December April 2014 1,46 1.46 1.76
      A 2 Orange 2015 December April 2014 1.76 1.46 1.76
      B 1 Peach 2014 December April
      2014
      1.85 1.85

      Comment


      • #4
        Is there any practical way of reorganizing data? I have values in one column. I just wanted to create additional columns based on this column.

        Comment

        Working...
        X