title: Stata dummy variables start date end date
body: <p>I want to rearrange dummy variables which are currently not in an usable format for Stata: I have a start date and an end date for different measures (&amp;different countries)- a dummy indicates &quot;1&quot; when the start date of the measure and the data-date &quot;date2&quot; equal. However, I need the dummy variable to be &quot;1&quot; until the end date (so the &quot;active&quot; measures).
  Any ideas how to solve this?</p>
  <pre><code>clear all
      sort country date2
      by country: replace M1=M1[_n-1] if date_end2&lt;=date2 &amp; date_end2&gt;0
  </code></pre>
  <p>My current code can't solve it, I don't know how to adress the end date right: (example for one Measure)
  It is quite complicated, as the same type of measures can also overlap.</p>
  <pre><code>
  * Example generated by -dataex-. To install: ssc install dataex
  clear
  input float date2 str3 country float(date_start2 date_end2 M1 M2 M3 M4 M5)
  21914 &quot;FRA&quot;     .     . . . . . .
  21915 &quot;FRA&quot;     .     . . . . . .
  21916 &quot;FRA&quot;     .     . . . . . .
  21917 &quot;FRA&quot;     .     . . . . . .
  21918 &quot;FRA&quot;     .     . . . . . .
  21919 &quot;FRA&quot;     .     . . . . . .
  21920 &quot;FRA&quot;     .     . . . . . .
  21921 &quot;FRA&quot;     .     . . . . . .
  21922 &quot;FRA&quot;     .     . . . . . .
  21923 &quot;FRA&quot;     .     . . . . . .
  21924 &quot;FRA&quot;     .     . . . . . .
  21925 &quot;FRA&quot;     .     . . . . . .
  21926 &quot;FRA&quot;     .     . . . . . .
  21927 &quot;FRA&quot;     .     . . . . . .
  21928 &quot;FRA&quot;     .     . . . . . .
  21929 &quot;FRA&quot;     .     . . . . . .
  21930 &quot;FRA&quot;     .     . . . . . .
  21931 &quot;FRA&quot;     .     . . . . . .
  21932 &quot;FRA&quot;     .     . . . . . .
  21933 &quot;FRA&quot;     .     . . . . . .
  21934 &quot;FRA&quot;     .     . . . . . .
  21935 &quot;FRA&quot;     .     . . . . . .
  21936 &quot;FRA&quot;     .     . . . . . .
  21937 &quot;FRA&quot;     .     . . . . . .
  21938 &quot;FRA&quot;     .     . . . . . .
  21939 &quot;FRA&quot;     .     . . . . . .
  21940 &quot;FRA&quot;     .     . . . . . .
  21941 &quot;FRA&quot;     .     . . . . . .
  21942 &quot;FRA&quot;     .     . . . . . .
  21943 &quot;FRA&quot;     .     . . . . . .
  21944 &quot;FRA&quot;     .     . . . . . .
  21945 &quot;FRA&quot;     .     . . . . . .
  21946 &quot;FRA&quot;     .     . . . . . .
  21947 &quot;FRA&quot;     .     . . . . . .
  21948 &quot;FRA&quot;     .     . . . . . .
  21949 &quot;FRA&quot;     .     . . . . . .
  21950 &quot;FRA&quot;     .     . . . . . .
  21951 &quot;FRA&quot;     .     . . . . . .
  21952 &quot;FRA&quot;     .     . . . . . .
  21953 &quot;FRA&quot;     .     . . . . . .
  21954 &quot;FRA&quot;     .     . . . . . .
  21955 &quot;FRA&quot;     .     . . . . . .
  21956 &quot;FRA&quot;     .     . . . . . .
  21957 &quot;FRA&quot;     .     . . . . . .
  21958 &quot;FRA&quot;     .     . . . . . .
  21959 &quot;FRA&quot;     .     . . . . . .
  21960 &quot;FRA&quot;     .     . . . . . .
  21961 &quot;FRA&quot;     .     . . . . . .
  21962 &quot;FRA&quot;     .     . . . . . .
  21963 &quot;FRA&quot;     .     . . . . . .
  21964 &quot;FRA&quot;     .     . . . . . .
  21965 &quot;FRA&quot;     .     . . . . . .
  21966 &quot;FRA&quot;     .     . . . . . .
  21967 &quot;FRA&quot;     .     . . . . . .
  21968 &quot;FRA&quot;     .     . . . . . .
  21969 &quot;FRA&quot;     .     . . . . . .
  21970 &quot;FRA&quot;     .     . . . . . .
  21971 &quot;FRA&quot;     .     . . . . . .
  21972 &quot;FRA&quot;     .     . . . . . .
  21973 &quot;FRA&quot;     .     . . . . . .
  21974 &quot;FRA&quot; 21974 22175 . . . 1 .
  21975 &quot;FRA&quot;     .     . . . . . .
  21976 &quot;FRA&quot;     .     . . . . . .
  21977 &quot;FRA&quot;     .     . . . . . .
  21978 &quot;FRA&quot;     .     . . . . . .
  21979 &quot;FRA&quot;     .     . . . . . .
  21980 &quot;FRA&quot;     .     . . . . . .
  21981 &quot;FRA&quot;     .     . . . . . .
  21982 &quot;FRA&quot;     .     . . . . . .
  21983 &quot;FRA&quot;     .     . . . . . .
  21984 &quot;FRA&quot;     .     . . . . . .
  21985 &quot;FRA&quot;     .     . . . . . .
  21986 &quot;FRA&quot;     .     . . . . . .
  21987 &quot;FRA&quot;     .     . . . . . .
  21988 &quot;FRA&quot;     .     . . . . . .
  21989 &quot;FRA&quot;     .     . . . . . .
  21990 &quot;FRA&quot; 21990 22045 1 . . . 1
  21991 &quot;FRA&quot; 21991 22046 . 1 . . 1
  21992 &quot;FRA&quot;     .     . . . . . .
  21993 &quot;FRA&quot;     .     . . . . . .
  21994 &quot;FRA&quot;     .     . . . . . .
  21995 &quot;FRA&quot;     .     . . . . . .
  21996 &quot;FRA&quot;     .     . . . . . .
  21997 &quot;FRA&quot;     .     . . . . . .
  21998 &quot;FRA&quot;     .     . . . . . .
  21999 &quot;FRA&quot;     .     . . . . . .
  22000 &quot;FRA&quot;     .     . . . . . .
  22001 &quot;FRA&quot;     .     . . . . . .
  22002 &quot;FRA&quot;     .     . . . . . .
  22003 &quot;FRA&quot;     .     . . . . . .
  22004 &quot;FRA&quot;     .     . . . . . .
  22005 &quot;FRA&quot;     .     . . . . . .
  22006 &quot;FRA&quot;     .     . . . . . .
  22007 &quot;FRA&quot;     .     . . . . . .
  22008 &quot;FRA&quot;     .     . . . . . .
  22009 &quot;FRA&quot;     .     . . . . . .
  22010 &quot;FRA&quot;     .     . . . . . .
  22011 &quot;FRA&quot;     .     . . . . . .
  22012 &quot;FRA&quot;     .     . . . . . .
  22013 &quot;FRA&quot;     .     . . . . . .
  end
  format %tdCCYY-NN-DD date2
  format %tdCCYY-NN-DD date_start2
  format %tdCCYY-NN-DD date_end2 
  
  
  </code></pre>