Hi,
I have a dataset with the following variables:
- Brand (41 brands in total)
- product identifier (identifies unique product and unique brand)
- Date started
- Date ended
- Brand start
- Brand end
ex:
product identifier brand date started date ended Brand start Brand end
101 A 2001 2002 1990 2010
102 A 2008 2010 1990 2010
I would like to analyze how many different products are produced by a given brand, year by year (generate a new dataset).
My initial idea was to create a duplicate my observations so that I now have a row for each year between brand start and brand end. I then wanted to sum columns X conditional on the brand name, and date started being before the year corresponding to the row, and date ended being after the year corresponding to the row.
product identifier brand date started date ended Brand start Brand end Year X Value of interest
101 A 2001 2002 1990 2010 1990 1 ?
A 1991 0
A 1992 0
...
102 A 2008 2010 1990 2010 1990 1
A 1992 0
Value of interest would be calculated by adding the value in the X column for each row that meet the criteria: for the value of interest, brand has to be A, date started has to be before 1990, date ended has to be after 1990.
I did this without any problems in Excel but I have no idea of how to do it with STATA. Any suggestions?
Thank you very much in advance.
Josh.
Related Posts with Conditional sum on STATA
5-year average data and lagged variableHello, I am new to this forum and I am currently writing my bachelor's thesis in international econ…
Time varying EWMA correlation matrixI am trying to calculate the time-varying EWMA correlation matrix in Stata when mean is not zero. C…
Identify Specific Letter/Numeric from a String VariableDear all, I have a list of countryname and countrycode, as follow: countrycode countryname 004 …
Generate visit number in a longitudinal datasetI have a longitudinal dataset and would like to generate a visit number for each patient. For exampl…
Difference in Difference with matching (DiDM) - Using two estimated propensity scoresHi I'm writing a paper evaluation a public school reform in Denmark. Since all the students got the…
Subscribe to:
Post Comments (Atom)
0 Response to Conditional sum on STATA
Post a Comment