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
Direct Standardisation- two in-built Stata methods, different resultsWhile doing analysis recently, I came across a peculiar problem. For reproducibility, the two .dta f…
to draw vertical line on kdensity ploti have generated kdensity plot using this code: kdensity mpce if year==2019 & household_type ==1…
Fixed effects panel regression with robust standard error- which code to use?Hi, I'm using the following code to perform fixed effects panel regression Code: areg y x1 x2 i.ye…
Simple Question from Begginner about Random Effects Panel DataHello everyone, I need help. What is Wald chi2 and Prob > chi2 means? Please help, thankyou Array…
How to clear all graphs saved in macroHi, I am 'foreach' loop command to save and combine 9 different catplot (ssc) graphs (local graphnam…
Subscribe to:
Post Comments (Atom)
0 Response to Conditional sum on STATA
Post a Comment